UIButton之所以能够显示图片和文字,是因为UIButton中有UIImageView属性和Label属性
设置按钮的文字的大小如下代码:
downloadBtn.titleLabel.font = [UIFont systemFontOfSize:13];
但是设置图片不能直接去Label和UIImageView属性直接进行设置,因为不知道按钮的状态,要用如下代码进行设置:
// 设置默认的背景
UIImage *normalImage = [UIImage imageNamed:@"buttongreen"];
[downloadBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
// 设置高亮的背景
UIImage *highImage = [UIImage imageNamed:@"buttongreen_highlighted"];
[downloadBtn setBackgroundImage:highImage forState:UIControlStateHighlighted];
// 设置按钮的文字
[downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
// 不推荐直接拿到按钮内部的label设置文字
// downloadBtn.titleLabel.text = @"5435345345";
// 设置按钮文字的字体
设置按钮的文字的大小如下代码:
downloadBtn.titleLabel.font = [UIFont systemFontOfSize:13];
但是设置图片不能直接去Label和UIImageView属性直接进行设置,因为不知道按钮的状态,要用如下代码进行设置:
// 设置默认的背景
UIImage *normalImage = [UIImage imageNamed:@"buttongreen"];
[downloadBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
// 设置高亮的背景
UIImage *highImage = [UIImage imageNamed:@"buttongreen_highlighted"];
[downloadBtn setBackgroundImage:highImage forState:UIControlStateHighlighted];
// 设置按钮的文字
[downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
// 不推荐直接拿到按钮内部的label设置文字
// downloadBtn.titleLabel.text = @"5435345345";
// 设置按钮文字的字体