sizeWithFont is an NSString method (UIKit add-ons). Application:
CGSize userInputSize = [userLabel.text sizeWithFont:[UIFont fontWithName:@"Arial" size:18.0f] constrainedToSize:[tableView frame].size lineBreakMode:NSLineBreakByWordWrapping];
or
CGSize userInputSize = [userLabel.text sizeWithFont:userLabel.font constrainedToSize:[tableView frame].size lineBreakMode:NSLineBreakByWordWrapping];
See the NCCtring UIKit Add-ons Help .
EDIT:
I just tried this code:
NSLog (@"test: %@", NSStringFromCGSize([@"test" sizeWithFont:[UIFont fontWithName:@"Arial" size:18.0f]])); NSLog (@"longer test: %@", NSStringFromCGSize([@"longer test" sizeWithFont:[UIFont fontWithName:@"Arial" size:18.0f]]));
and the result:
test: {30, 22} longer test: {85, 22}
CGSize is a struct :
struct CGSize { CGFloat width; CGFloat height; }; typedef struct CGSize CGSize;
So you are probably looking at size.height instead of size.width
EDIT2:
from the documentation sizeWithFont: forWidth: lineBreakMode:
If the line size exceeds the specified width, this method truncates the text (for layout purposes only), using the specified line interrupt mode until it matches the maximum width; it returns the size of the resulting truncated string.
So, you better determine the maximum size (real width and large height ) and go with:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
See this answer .
source share