Swift - 按钮(UIButton)的用法
1,按钮的创建
(1)按钮有下面四种类型:
(2)对于Custom定制类型按钮,代码可简化为:
1
(1)按钮有下面四种类型:
UIButtonType.InfoDark:为感叹号“!”圆形按钮
UIButtonType.InfoLight:为感叹号“!”圆形按钮
1
2
3
4
5
6
7
|
//创建一个ContactAdd类型的按钮
let
button:
UIButton
=
(type:.
ContactAdd
)
//设置按钮位置和大小
button.frame=
CGRectMake
(10,150,100,30)
//设置按钮文字
button.setTitle(
"按钮"
,forState:
UIControlState
.
Normal
)
self
.view.addSubview(button);
|
button =
(frame:
|