iOS button文字居中

新建一个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了

  

posted on 2016-11-30 12:32  奉灬孝  阅读(1935)  评论(0编辑  收藏  举报

导航