字體宏
#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中動態(tài)計算高度的方法
+ (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;
}
問題表現(xiàn):
- iOS 9.0+ 高度計算正常
- iOS 10.0+ 6p/6sp/7p 種高度計算不正常
問題場景
使用.xib
創(chuàng)建的UITableViewCell
,使用.xib
的方案設置的UITableViewCell
的布局和字體,字號恶座。
問題排查
...
問題原因
///iOS 10 plus 設備中 systemFont 跟自定義font 的高度不統(tǒng)一橡卤,由于xib中iOS10會顯示sc font斧账,但是代碼計算采用的font 宏定義在iOS10中卻計算的是systemfont的高度,所以造成iOS10 p設備中字體計算有偏差