Swift-代码实现基础UI组件

2015-12-08  本文已影响0人  MadsSpec

1.UIButton 通过IB实现就不记录了。

//声明

var MyButton:UIButton

//在viewDidLoad()中初始化控件,注意在设定组件属性是使用到的枚举。

MyButton = UIButton.buttonWithType(UIButtonType.Syetem) as! Button

MyButton.setTitle("注册",forState:  UIControlState.Normal)

MyButton.setImage(UIIamge(name: "1.jpg"),forState:UIControlState.Normal)

MyButton.frame = CGRect(x: 10, y: 30, width: 100, height:40)

MyButton.addTarget(self,action:"Click:",forControlEvents: UIControlEvents.TouchUpInside)

self.view,addSubview(self.MyButton)

//定义addTarget中设定的方法

func Click(sender:UIButton){ println("OnClick") }

上一篇 下一篇

猜你喜欢

热点阅读