大家看到题目应该就知道我要说的东西了,今天要给大家介绍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,最近做项目要用。
总结以上是内存溢出为你收集整理的Swift-UIButton&AlertView全部内容,希望文章能够帮你解决Swift-UIButton&AlertView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)