- 按钮垂直对齐方式
@property(nonatomic) UIControlContentVerticalAlignment contentVerticalAlignment;
typedef NS_ENUM(NSInteger, UIControlContentVerticalAlignment) {
UIControlContentVerticalAlignmentCenter = 0,
UIControlContentVerticalAlignmentTop = 1,
UIControlContentVerticalAlignmentBottom = 2,
UIControlContentVerticalAlignmentFill = 3,
};
- 按钮水平对齐方式
@property(nonatomic) UIControlContentHorizontalAlignment contentHorizontalAlignment;
typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
UIControlContentHorizontalAlignmentCenter = 0,
UIControlContentHorizontalAlignmentLeft = 1,
UIControlContentHorizontalAlignmentRight = 2,
UIControlContentHorizontalAlignmentFill = 3,
UIControlContentHorizontalAlignmentLeading API_AVAILABLE(ios(11.0), tvos(11.0)) = 4,
UIControlContentHorizontalAlignmentTrailing API_AVAILABLE(ios(11.0), tvos(11.0)) = 5,
};
设置按钮文字左对齐
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
设置按钮文字与边框距离
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);