首先看一下 UIButton的属性
@property(nonatomic) UIControlContentHorizontalAlignment contentHorizontalAlignment; // how to position content hozontally inside control. default is center
typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
UIControlContentHorizontalAlignmentCenter = 0,
UIControlContentHorizontalAlignmentLeft = 1,
UIControlContentHorizontalAlignmentRight = 2,
UIControlContentHorizontalAlignmentFill = 3,
};
设置UIButton字体居左显示
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
设置button的title就距左边10个像素的距离。
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
UIEdgeInsets的属性
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
} UIEdgeInsets;
网友评论