美文网首页
iOS UIButton文字和图片随意改变位置,左右上下

iOS UIButton文字和图片随意改变位置,左右上下

作者: 新生的光明 | 来源:发表于2018-02-02 10:36 被阅读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
image.png

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

代码地址

相关文章

网友评论

      本文标题:iOS UIButton文字和图片随意改变位置,左右上下

      本文链接:https://www.haomeiwen.com/subject/dppszxtx.html