我正在尝试摆脱iOS 7中已弃用的功能,而我正在运行一些我不理解的功能。这是我现在的代码:
CGFloat titleHeight = [[object name] sizeWithFont:[UIFont fontWithName:@"Abel" size:24.0f] constrainedToSize:CGSizeMake(170.0f, 200.0f) lineBreakMode:NSLineBreakByWordWrapping].height;
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
CGFloat titleHeight2 = [[object name] boundingRectWithSize:CGSizeMake(170.0f, 200.0f) options:0 attributes:@{NSFontAttributeName: [UIFont fontWithName:@"Abel" size:24.0f], NSParagraphStyleAttributeName: paragraphStyle} context:nil].size.height;
出于某种原因,titleHeight
和titleHeight2
最终会成为不同的值,我无法弄清楚原因。有任何想法吗?谢谢!