大家看到题目应该就知道我要说的东西了,今天要给大家介绍button控件,也是比较常用的用法。我就不啰嗦什么了。直接上代码:
var myButton: UIButton!
//Attention: buttonWithType return the type of AnyObject
myButton = UIButton.buttonWithType(.System) as? UIButton(这里有必要说明一下,buttonWithType最终返回的是一个AnyObject,所以这里要用到类型转换)
//Set the location and size of button
myButton.frame = CGRectMake(110,70,200, 100)
//Add a name to button,and set state
myButton.setTitle("Press Me",forState: .Normal)
myButton.setTitle("I`m Pressed",forState: .Highlighted)
//Add action to button
myButton.addTarget(self,action: "buttonIspressed:",forControlEvents: .TouchDown)
myButton.addTarget(self,action: "buttonIsTaped:",forControlEvents: .TouchUpInside)
//Add backgroundColor
myButton.backgroundColor = UIColor.greenColor()
//Add image to backgound of myButton
var image = UIImage(named: "pg.jpg")
myButton.setBackgroundImage(image,forState: .Normal)
view.addSubview(myButton)
到这里button的用法差不多就讲完了。下面我要说的是AlertView,不是AlertViewController。大家看仔细:
myAlertView = UIAlertView(title: "Done",message: "The button is tapped",delegate: self,cancelButtonTitle: "Cancell",otherButtonTitles: "ok")
myAlertView!.show()
Ok,今天就说这么多了。明天一个下载图片的demo,最近做项目要用。