UIButton(左边图片右边文字)

normal

highlighted
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor clearColor];
//设置button正常状态下的图片
[button setImage:[UIImage imageNamed:@"_star_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的图片
[button setImage:[UIImage imageNamed:@"_star_highlighted.png"] forState:UIControlStateHighlighted];
//设置button正常状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_highlighted.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];
[self.view addSubview:button];

你可能感兴趣的:(UIButton(左边图片右边文字))