iOS button文字居中

Posted 奉灬孝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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了

  

以上是关于iOS button文字居中的主要内容,如果未能解决你的问题,请参考以下文章