记一个小问题,在 iOS8下,貌似也不是所有8的系统,也不去纠结这个,
NSMutableAttributedString *calStr = [[NSMutableAttributedString alloc] initWithString:title];
[calStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, title.length)];
// [calStr addAttribute:NSBaselineOffsetAttributeName value:@0 range:NSMakeRange(0, title.length)];
CGSize calSize = CGSizeMake(200, 14);
CGSize size = [calStr boundingRectWithSize:calSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;
NSLog(@"size = %@", NSStringFromCGSize(size));
这样直接计算出来的高度为 0
size = {0, 0}
解决,就是把注释打开,增加 NSBaselineOffsetAttributeName
属性,这样输出的高度就是正确的了。