Swift 常用控件的创建

Swift 常用控件的创建,第1张

概述1、UILabel let label:UILabel = UILabel.init(frame: CGRectMake(50, 50, 100, 30))label.text = "Test"label.textColor = UIColor.redColor()label.font = UIFont.systemFontOfSize(20.0)label.backgroundColor 1、UILabel
let label:UILabel = UILabel.init(frame: CGRectMake(50,50,100,30))label.text = "Test"label.textcolor = UIcolor.redcolor()label.Font = UIFont.systemFontOfSize(20.0)label.backgroundcolor = UIcolor.orangecolor()label.textAlignment = NSTextAlignment.Center;self.vIEw .addSubvIEw(label)
2、UIbutton
func createbutton() {     let button = UIbutton(type: UIbuttonType.System)     button.frame = CGRectMake(50,50)     button.setTitle("确定",forState: UIControlState.normal)     button.setTitlecolor(UIcolor.whitecolor(),forState: UIControlState.normal)     button.backgroundcolor = UIcolor.orangecolor()     button.TitleLabel?.Font = UIFont.systemFontOfSize(20)     button.addTarget(self,action: "btnClick:",forControlEvents: UIControlEvents.touchUpInsIDe)     button.layer.cornerRadius = 5.0     self.vIEw.addSubvIEw(button)    }func btnClick(button:UIbutton) {     button.backgroundcolor = UIcolor.redcolor()    }
3、UITextFIEld
let account:UITextFIEld = UITextFIEld.init(frame: CGRectMake(50,200,30))account.placeholder = "请输入账号"account.textcolor = UIcolor.orangecolor()account.Font = UIFont.systemFontOfSize(20)account.borderStyle = UITextborderStyle.RoundedRectself.vIEw .addSubvIEw(account)
4、UIImageVIEw
let imageVIEw:UIImageVIEw = UIImageVIEw(image:UIImage(named:"123"))imageVIEw.frame = CGRectMake(50,100)imageVIEw.backgroundcolor = UIcolor.orangecolor()self.vIEw .addSubvIEw(imageVIEw)
5、UItableVIEw
import UIKitclass VIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDataSource {    var datas = ["1","2","3","4"]    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        let tableVIEw:UItableVIEw = UItableVIEw(frame: self.vIEw.bounds,style: UItableVIEwStyle.Plain)        tableVIEw.delegate = self        tableVIEw.dataSource = self        self.vIEw.addSubvIEw(tableVIEw)    }    func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int {        return 1    }    func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {        return datas.count    }    func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {        let IDentifIEr = "CELL"        let cell = UItableVIEwCell(style: UItableVIEwCellStyle.SubTitle,reuseIDentifIEr: IDentifIEr)        cell.textLabel?.text = datas[indexPath.row]        cell.detailTextLabel?.text = "Test"        return cell    }    func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {        NSLog("我被点击了%ld",indexPath.row)    }}
总结

以上是内存溢出为你收集整理的Swift 常用控件创建全部内容,希望文章能够帮你解决Swift 常用控件的创建所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1078121.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存