Button 左图片右文字

2018-08-20  本文已影响6人  andrewliu20
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor clearColor];
//设置button正常状态下的图片
[button setImage:[UIImage imageNamed:@"图片.png"] forState:UIControlStateNormal];
//设置button高亮状态下的图片
[button setImage:[UIImage imageNamed:@"图片.png"] forState:UIControlStateHighlighted];
//设置button正常状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"背景图片.png"] forState:UIControlStateNormal];
//设置button高亮状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"背景图片.png"] forState:UIControlStateHighlighted];
//button图片的偏移量,距上左下右分别(10, 10, 10, 60)像素点
button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 60);
[button setTitle:@"文字" forState:UIControlStateNormal];
//button标题的偏移量,这个偏移量是相对于图片的
button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//设置button正常状态下的标题颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//设置button高亮状态下的标题颜色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont systemFontOfSize:14];
上一篇下一篇

猜你喜欢

热点阅读