UIButton的图文位置,网上有很多方法,这里介绍一种简单的方式,一句话搞定.
@interface UIButton (Add)
/**
*style:内容的位置,
*space:图片和文字之间的距离
*offset:内容距离边界的偏移
*/
- (void)layoutButtonWithEdgeInsetsStyle:(UIButtonEdgeInsetsStyle)style
imageTitleSpace:(CGFloat)space offset:(CGFloat)offset;
@end
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//内容左对齐
[btn layoutButtonWithEdgeInsetsStyle:UIButtonEdgeInsetsStyleRight imageTitleSpace:5 offset:10];//图片在右边,图文间距5,内容距btn左边界10
![](https://img.haomeiwen.com/i10417199/0a69c24cfc442669.png)
搞一个类别,就这么简单!!!
网友评论