iOS UIButton文字和图片随意改变位置,左右上下
2018-02-02 本文已影响0人
新生的光明
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

搞一个类别,就这么简单!!!