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