iOS開(kāi)發(fā)過(guò)程中,公司的psd對(duì)文字標(biāo)簽的標(biāo)注很多時(shí)候無(wú)法適配字體,這時(shí)就需要自己去剝離出一個(gè)方法,直接貼代碼!!!
/** 直接給UIFonto寫(xiě)個(gè)工具類 以下為.h文件 */
@interface UIFont (Fit)
/** 正常字體上修改*/
+ (UIFont *)systemFontWithSize:(CGFloat)fontSize;
/** 粗體字體上修改 */
+(UIFont *)boldSystemFontWithSize:(CGFloat)fontSize;
@end
接下來(lái).m文件去實(shí)現(xiàn)它 以下代碼
@implementation UIFont (Fit)
+ (UIFont *)systemFontWithSize:(CGFloat)fontSize{
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone && KScreenHeight == 568.0) {
return [UIFont systemFontOfSize:fontSize * 0.8];
}else if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone && KScreenHeight == 736.0){
return [UIFont systemFontOfSize:fontSize*1.1];
}else{
return [UIFont systemFontOfSize:fontSize];
}
}
+(UIFont *)boldSystemFontWithSize:(CGFloat)fontSize{
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone && KScreenHeight == 568.0) {
return [UIFont boldSystemFontOfSize:fontSize * 0.8];
}else if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone && KScreenHeight == 736.0){
return [UIFont boldSystemFontOfSize:fontSize*1.1];
}else{
return [UIFont boldSystemFontOfSize:fontSize];
}
}