加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift-UIButton&AlertView

发布时间:2020-12-14 02:14:56 所属栏目:百科 来源:网络整理
导读:大家看到题目应该就知道我要说的东西了,今天要给大家介绍button控件,也是比较常用的用法。我就不啰嗦什么了。直接上代码: var myButton: UIButton ! //Attention: buttonWithType return the type of AnyObject myButton = UIButton . buttonWithType (.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读