iOS适配字体

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];
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容