设置UIButton的文字样式,一般都会想到用设置UIButton的titleLable的textAligent属性,但是, Invalid! 下面是有效设置按钮文字居中、左、右的方法:
typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
UIControlContentHorizontalAlignmentCenter = 0,
UIControlContentHorizontalAlignmentRight = 2,
UIControlContentHorizontalAlignmentFill = 3,
UIControlContentHorizontalAlignmentLeading API_AVAILABLE(ios(11.0), tvos(11.0)) = 4,
UIControlContentHorizontalAlignmentTrailing API_AVAILABLE(ios(11.0), tvos(11.0)) = 5,
};
文字居右设置
[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];










网友评论