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