iOS13 及以后的版本中,当用户在手机设置中,将字体设置为加粗后,会导致我们的图片+文字按钮出现显示问题,文字显示不全。
self.allBtn.titleLabel.lineBreakMode=NSLineBreakByClipping;
设置titleLabel的剪切模式即可
//另一种方式,写一个TJUIButton继承UIButton,然后使用TJUIButton
@interface TJUIButton : UIButton
@end
@implementation TJUIButton
-(instancetype)initWithCoder:(NSCoder *)coder{
if(self = [super initWithCoder:coder]){
[self fixBoldTextBug];
}
return self;
}
- (void)setImage:(UIImage *)image forState:(UIControlState)state{
UIImage * fiximage = [image resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
[super setImage:fiximage forState:state];
}
- (void)fixBoldTextBug{
UIImage * normalImage = [ self imageForState:UIControlStateNormal];
if(normalImage){
UIImage * norImageResize = [normalImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
[self setImage:norImageResize forState:UIControlStateNormal];
}
}
@end