UIButton


一、UIButton 基本属性

1 创建UIButton 对象

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
:> 注意:设置按钮的类型只能在初始化的时候设置 ->UIButtonTypeCustom

2 设置Frame

button.frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height);

3 设置背景颜色

button.backgroundColor = [UIColor redColor]; 

4 设置文字

[button setTitle:@"普通按钮" forState:UIControlStateNormal];//普通状态:
[button setTitle:@"高亮按钮" forState:UIControlStateHighlighted];//高亮状态

5 设置文字的颜色

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

6 设置文字的阴影颜色

# 普通状态:
[button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];

# 高亮状态:
[button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

button.titleLabel.shadowOffset = CGSizeMake(3, 2);

7 设置内容图片

# 普通状态:
[button setImage:[UIImage imageNamed:@"btn_normal"] forState:UIControlStateNormal];

# 高亮状态:
[button setImage:[UIImage imageNamed:@"btn_highlight"] forState:UIControlStateHighlighted];

8 设置背景图片

# 普通状态:
[button setBackgroundImage:[UIImage imageNamed:@"btn"] forState:UIControlStateNormal];
# 高亮状态:
[button setBackgroundImage:[UIImage imageNamed:@"btn_highlighted"] forState:UIControlStateHighlighted];

你可能感兴趣的:(UIButton)