微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift-UIButton&AlertView

大家看到题目应该就知道我要说的东西了,今天要给大家介绍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,最近做项目要用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐