解决升级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字体适配问题(下)
网友评论