iOS开发过程中,公司的psd对文字标签的标注很多时候无法适配字体,这时就需要自己去剥离出一个方法,直接贴代码!!!
/** 直接给UIFonto写个工具类 以下为.h文件 */
@interface UIFont (Fit)
/** 正常字体上修改*/
+ (UIFont *)systemFontWithSize:(CGFloat)fontSize;
/** 粗体字体上修改 */
+(UIFont *)boldSystemFontWithSize:(CGFloat)fontSize;
@end
接下来.m文件去实现它 以下代码
@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];
}
}