- (CGSize)sizeWithFont:(UIFont *)font
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode
The below code can obtain the height.
CGSize boundSize = CGSizeMake(desiredWidth, CGFLOAT_MAX);
CGSize myTextSize = [myText sizeWithFont:myFont constrainedToSize:boundSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat myTextHeight = myTextSize.height;
Remark:
Use CGFLOAT_MAX (or a big number) for the height value in CGSizeMake method.
No comments:
Post a Comment