簡介:主要的思路是獲取手機系統(tǒng)版本號滔蝉,如果是10以上的版本那么就做相應(yīng)的處理红符,這里是做label寫了一個分類,如果用戶手機的版本大于等于 10 ?那么字體都-0.5
如有疑問:請加群:246807516? 此乃活躍群,進群不改備注者功咒,秒提旁赊,不經(jīng)常發(fā)言者桦踊,按時清人,自己看情況加群终畅,拒絕死人籍胯,謝謝合作
.h里一個方法+屬性
#import@interface UILabel (FitFont)
@property (nonatomic, assign) BOOL change;
- (void)fitFontSize;
@end
.m里一定要引入runtime頭文件哦#import <objc/runtime>
@implementation UILabel (FitFont)
static char *UILabelChangeKey = "UILabelChangeKey";
- (void)setChange:(BOOL)change {
objc_setAssociatedObject(self, UILabelChangeKey, @(change), OBJC_ASSOCIATION_ASSIGN);
}
-(BOOL)change{
return objc_getAssociatedObject(self, UILabelChangeKey);
}
- (instancetype)init{
self = [super init];
if (self) {
[self fitFontSize];
}return self;}
- (void)fitFontSize{
//? ? self.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline];
if ([kSystemVersion floatValue] >= 10) {//iPhone系統(tǒng)版本是10 所有的字體變小
if(!self.change) {
CGFloat fonts = self.font.pointSize;
fonts -= 0.5;
NSString *fontN = self.font.fontName;
self.font = [UIFont fontWithName:fontN size:fonts];
NSLog(@" label的大小 == %f", self.font.pointSize);
self.change = YES;
}
}
}