解决IOS10字体适配问题(上)

解决升级IOS10后由于字体的点数改变导致部分布局出现显示不全(显示为 ... )的情况

首先, 咱们先解决纯代码布局问题,.................

// 核心代码, 是否启用字体重定向, 呵呵!!
#define UseFontManager 1UL

#ifdef UseFontManager
#define SysFont(x)   [UIFont sc_systemFontOfSize:(x)]
#define BoldFont(x)  [UIFont sc_boldSystemFontOfSize:(x)]
#else
#define SysFont(x)   [UIFont systemFontOfSize:(x)]
#define BoldFont(x)  [UIFont boldSystemFontOfSize:(x)]
#endif

@interface UIFont(sma11case_IOS)
+ (instancetype)sc_systemFontOfSize: (CGFloat)fontSize;
+ (instancetype)sc_boldSystemFontOfSize: (CGFloat)fontSize;
@end
static double gs_sysVer = 0.0;

@implementation UIFont(sma11case_IOS)
+ (instancetype)sc_boldSystemFontOfSize: (CGFloat)fontSize
{
    if (!gs_sysVer)
    {
        NSString *ver = [[UIDevice currentDevice].systemVersion regexpFirstMatch:@"^\\d+(\\.\\d+)*"];
        gs_sysVer = atof(ver.UTF8String);
    }
    
    if (gs_sysVer >= 10.0)
    {
        CGFloat p = fontSize * 17 / 17.5;
        MLog(@"convert bold font: %f => %f", fontSize, p);
        fontSize = p;
    }
    
    return [UIFont boldSystemFontOfSize:fontSize];
}

+ (instancetype)sc_systemFontOfSize: (CGFloat)fontSize
{
    if (!gs_sysVer)
    {
        NSString *ver = [[UIDevice currentDevice].systemVersion regexpFirstMatch:@"^\\d+(\\.\\d+)*"];
        gs_sysVer = atof(ver.UTF8String);
    }
    
    if (gs_sysVer >= 10.0)
    {
        CGFloat p = fontSize * 17 / 17.5;
        MLog(@"convert bold font: %f => %f", fontSize, p);
        fontSize = p;
    }
    
    return [UIFont systemFontOfSize:fontSize];
}
@end

解决IOS10字体适配问题(下)

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

推荐阅读更多精彩内容