You can use the NSString UIKIT Addition method
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode
to calculate the height. sort of.
CGSize yourLabelSize = [@"Your very long text" sizeWithFont:yourFont constrainedToSize:CGSizeMake(desiredMaximumWidth, 2000) lineBreakMode:NSLineBreakByWordWrapping];
itβs really important to understand the constrainedToSize parameter. You have to go through CGSize with the width desired maximum and maximum possible height . Use the same UIFont with your tag. Do not forget to install
[yourLabel setNumberOfLines:0]
But the method is already deprecated in iOS 7 , so you should use
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context
yourLabelSize.height will give you the height
hope this helps you ...
source share