高就不能設死,如果設太小,落落長的語言如西文和德文,就會 truncated,
設太多又會讓簡短的繁簡中留有太多空白,這時就可以用計算的方式來設得剛剛好。
+ (CGFloat)getMaximalHeightForText:(NSString *)text withFont:(UIFont *)font withWidth:(CGFloat)width { CGRect frame = [text boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) // Give CGFLOAT_MAX for height to calculate desired height. options:(NSLineBreakByWordWrapping | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:font} context:nil]; return frame.size.height+5; // 5 is added for compensation. }