发布于 2015-12-27 10:04:52 | 332 次阅读 | 评论: 0 | 来源: 网友投递
Swift编程语言
SWIFT,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序。
UIButton 设置fram
let textButton = UIButton(frame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height))
设置title
textButton.setTitle(“button”,forState: UIControlState.Normal)
设置button 的title color
textButton.setTitleColor(redColor, forState: UIControlState.Normal)
设置button的显示图片
var backImage = UIImage(named:“icon114.png”)
textButton.setImage(backImage, forState : UIControlState.Normal)
给button添加事件
textButton.addTarget(self,action:“buttonActions:”,forControlEvents:UIControlEvents.TouchUpInside)
给button设置背景颜色
var whitColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:1.0)
textButton.backgroundColor = whitColor
self.view.addSubview(textButton)
响应button的事件
func buttonActions(sender: UIButton!) {
println(“tapped button”)
}