您的位置:首页 > 产品设计 > UI/UE

IOS开发笔记之十九——UIButton的使用总结

2015-01-14 19:36 337 查看
1、基本属性

//设置UIButton标题:

[button setTitle:@"title" forState:UIControlStateNormal];

//设置UIButton标题颜色:

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//设置UIButton背景图片和填充图片:

[button setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];

//设置UIButton背景颜色:

button.backgroundColor = [UIColor clearColor];

//设置UIButton按钮字体的大小:

button.titleLabel.font = [UIFont systemFontOfSize:26.0];//设置按钮上字体的大小

[button setTintColor:[UIColor whiteColor]];

2、button添加点击事件

[button addTarget:self action:@selector(onAction) forControlEvents:UIControlEventTouchUpInside];

addTarget:self 是链接到self,一般都这样设置

action:@selector(alarmTimeDone:) 时间处理函数

forControlEvents:UIControlEventTouchUpInside 控件事件处理的消息

删除点击事件,用下面方法:

- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

3、image与title属性的设置。。

4、未完待续。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: