Swift-UIButton
2016-07-14 18:53
337 查看
// let bt = UIButton(frame:CGRectMake(10,20,50,50))
let button = UIButton(frame:CGRectMake(10, 150, 100, 30)) //初始化按钮和设置按钮位置与大小
button.backgroundColor = UIColor.grayColor() //设置按钮的背景颜色
//button.setTitle("确定", forState: UIControlState.Normal) //普通状态下的文字
button.setTitle("确定", forState: UIControlState.Highlighted) //点击状态下显示文字
button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal) //设置按钮文字的颜色
button.setImage(UIImage(named: "1"), forState: .Normal) //设置按钮的背景图片
button.addTarget(self, action: #selector(tapped(_:)), forControlEvents: UIControlEvents.TouchUpInside) //按钮的触发事件
self.view.addSubview(button)
func tapped(bt:UIButton) {
print("1231313")
}
let button = UIButton(frame:CGRectMake(10, 150, 100, 30)) //初始化按钮和设置按钮位置与大小
button.backgroundColor = UIColor.grayColor() //设置按钮的背景颜色
//button.setTitle("确定", forState: UIControlState.Normal) //普通状态下的文字
button.setTitle("确定", forState: UIControlState.Highlighted) //点击状态下显示文字
button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal) //设置按钮文字的颜色
button.setImage(UIImage(named: "1"), forState: .Normal) //设置按钮的背景图片
button.addTarget(self, action: #selector(tapped(_:)), forControlEvents: UIControlEvents.TouchUpInside) //按钮的触发事件
self.view.addSubview(button)
func tapped(bt:UIButton) {
print("1231313")
}
相关文章推荐
- swift 中拨电话的实现
- 使用 Swift 在 iOS 10 中集成 Siri —— SiriKit 教程
- Swift利用协议优化NSNotificationCenter
- 初学Swift _闭包
- Swift编写规范
- 自学swift (5) --- 运算符 (后续补充中)
- swift版本的图片轮播(借鉴于前辈的思路)
- 【Swift】-- 开源项目侧边栏仿QQ菜单类似 android SlidingMenu
- Swift语法精炼(3)-数组与字典
- Swift语法精炼(2)-断言,基础运算,字符串
- Swift编程(一):UITableView及自定义Cell的Xib
- Swift语法精炼(1)-基础数据类型,元组,可选类型
- 细说Swift类型转换
- 写给小白的Swift基本运算符教程
- Swift编程(二):UIViewController之间的传值以及闭包回调传值
- Swift cell的自适应高度
- swift NSDate
- 极光推送不成功,Not get deviceToken yet
- iOS开发 - Swift使用GCD实现计时器功能
- change swift compile version in xcode build settings