按钮设置了文字和图片,若宽度足够展开的话,默认都是图片在作,文字在右。想文字在左,图片在右有两种方法。 第一种方法很简单。通过设置setSemanticContentAttribute属性来实现。
_bgBtn2 = [[UIButton alloc] init];
[_bgBtn2 setBackgroundColor:[UIColor clearColor]];
[_bgBtn2 setTitle:@"关注问题(243)" forState:UIControlStateNormal];
[_bgBtn2.titleLabel setFont:[UIFont systemFontOfSize:12]];
[_bgBtn2 setTitleColor:DYHighlightColor forState:UIControlStateNormal];
[_bgBtn2 setImage:[UIImage imageNamed:@"icon_quest31"] forState:UIControlStateNormal];
**[_bgBtn2 setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];**
第二种方法是通过设置titleEdgeInsets和setImageEdgeInsets来实现。
_selectBtn = [[BGSwapButton alloc] initWithTitle:@"排序" titleColor:DEFAULT_TITLE_LIGHT_FRONT_COLOR selectedTitleColor:DYHighlightColor icon:[UIImage imageNamed:@"icon_quest32"] selectedIcon:[UIImage imageNamed:@"icon_quest_sort"] frame:CGRectMake(FULL_WIDTH-40-COMMON_EDGE_DISTANCE, 12+100+12+28+12+8+(45-12.0)/2, 40, 12)];
_selectBtn.titleLabel.font = BGFont(12);
**_selectBtn.titleEdgeInsets=UIEdgeInsetsMake(0, -(40 -9)+8,0, 0);//上左下右
[_selectBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 40-9, 0, 0)];//上左下右**
|