BlueSky
BlueSky

Reputation: 139

IOS - Get height NSString

How i can get height absolutely of NSString, because I'm trying to do the following:

NSString *text = "Hello word, i'm a programer";
CGSize maximumSize = CGSizeMake(300, 9999);

UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:12];

CGSize myStringSize = [text sizeWithFont:myFont
                       constrainedToSize:maximumSize
                           lineBreakMode:NSLineBreakByWordWrapping];

NSLog(@"myStringSize %f",myStringSize.height);

I find it in this site but I think it do not ok.

Upvotes: 1

Views: 916

Answers (1)

evenodd
evenodd

Reputation: 2126

Use this:

CGSize maximumSize = CGSizeMake(300, 9999);
NSString *myString = @"This is a long string which wraps";
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:14];
CGSize myStringSize = [myString sizeWithFont:myFont 
                       constrainedToSize:maximumSize 
                           lineBreakMode:self.myLabel.lineBreakMode];

Your code isn't working because you are not using an NSString!

Upvotes: 5

Related Questions