我正在创建一个左侧图像和中心文本的按钮。它可以工作,但不知何故,红色的背景颜色并没有覆盖整个按钮。
self.buyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.buyButton.titleLabel setBackgroundColor:[UIColor buttonRed]];
UIImage *image = [UIImage imageNamed:@"cart.png"];
[self.buyButton setImage:image forState:UIControlStateNormal];
self.buyButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[self.buyButton setTitle:@"Buy" forState:UIControlStateNormal];
self.buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
self.buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[1] http://s23.postimg.org/g8hxmihyv/Screen_Shot_2013_08_07_at_5_45_40_PM.png “快照”
如果我将整个按钮设置为红色,它看起来像这样。[1] http://s21.postimg.org/xdwrziphv/Screen_Shot_2013_08_07_at_5_50_15_PM.png “快照2”