字体宏
#define FontPingFangSC_Regular(s) IS_IOS_VERSION(9.0)?[UIFont fontWithName:@"PingFangSC-Regular" size:s]:[UIFont systemFontOfSize:s/1.0f]
#define FontPingFangSC_Light(s) IS_IOS_VERSION(9.0)?[UIFont fontWithName:@"PingFangSC-Light" size:s]:[UIFont systemFontOfSize:s/1.0f]
#define FontPingFangSC_Medium(s) IS_IOS_VERSION(9.0)?[UIFont fontWithName:@"PingFangSC-Medium" size:s]:[UIFont systemFontOfSize:s/1.0f]
#define FontPingFangSC_Semibold(s) IS_IOS_VERSION(9.0)?[UIFont fontWithName:@"PingFangSC-Semibold" size:s]:[UIFont systemFontOfSize:s/1.0f]"
//UITableViewCell中动态计算高度的方法
+ (CGFloat) heightForCellWithData:(NSDictionary *)data {
CGFloat imageHeight = (ScreenWidth-15*2)*38/69; CGFloat contentHeight = [Helper getSizeWithStr:[NSString stringWithFormat:@"%@",data[@"introduction"]] width:(ScreenWidth-15*2) font:FontPingFangSC_Semibold(14)].height; CGFloat hideButton = 0; return imageHeight+15+contentHeight+hideButton;
}
问题表现:
- iOS 9.0+ 高度计算正常
- iOS 10.0+ 6p/6sp/7p 种高度计算不正常
问题场景
使用.xib
创建的UITableViewCell
,使用.xib
的方案设置的UITableViewCell
的布局和字体,字号。
问题排查
...
问题原因
///iOS 10 plus 设备中 systemFont 跟自定义font 的高度不统一,由于xib中iOS10会显示sc font,但是代码计算采用的font 宏定义在iOS10中却计算的是systemfont的高度,所以造成iOS10 p设备中字体计算有偏差