新建一个UIButton的category
.h
@interface UIButton (QXTitleInCenter) -(instancetype)init; @end
.m
@implementation UIButton (QXTitleInCenter) -(instancetype)init{ self = [super init]; self.contentEdgeInsets = UIEdgeInsetsMake(-(self.intrinsicContentSize.height) * 0.18(调节文字上下高度的,数值越大文字越靠上方),0, 0, 0); return self; } @end
然后引入这个category,直接用UIButton就OK了