
let button = UIbutton(type: UIbuttonType.Custom)
// 添加到父视图,并设置frameself.vIEw.addSubvIEw(button)button.frame = CGRectMake(10.0,10.0,200.0,40.0)
// 背景属性设置button.backgroundcolor = UIcolor.yellowcolor()// button.setBackgroundImage(UIImage(named: "normalimage"),forState: UIControlState.normal)// button.setBackgroundImage(UIImage(named: "hightimage"),forState: UIControlState.Highlighted)
// 图标设置button.setimage(UIImage(named: "normalimage"),forState: UIControlState.normal)button.setimage(UIImage(named: "hightimage"),forState: UIControlState.Highlighted)button.imageEdgeInsets = UIEdgeInsetsMake(0.0,-50.0,0.0,0.0)
// 标题设置button.setTitle("button",forState: UIControlState.normal)button.setTitlecolor(UIcolor.blackcolor(),forState: UIControlState.normal)button.setTitlecolor(UIcolor.redcolor(),forState: UIControlState.Highlighted)button.setTitleShadowcolor(UIcolor.greencolor(),forState: UIControlState.normal)button.TitleLabel?.Font = UIFont(name: "GillSans",size: 20.0)button.TitleEdgeInsets = UIEdgeInsetsMake(0.0,-50.0) button.selected = falsebutton.enabled = truebutton.userInteractionEnabled = true
// 响应事件button.addTarget(self,action: Selector("buttonClick:"),forControlEvents: UIControlEvents.touchUpInsIDe) // 响应事件func buttonClick(button:UIbutton) -> VoID{ button.selected = !button.selected if button.selected == true { print("选中按钮") let buttonTitle = button.TitleLabel?.text print(buttonTitle) } else { print("未选中按钮") }} 总结
以上是内存溢出为你收集整理的swift中UIButton的使用全部内容,希望文章能够帮你解决swift中UIButton的使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)