1

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.

Community
  • 1
  • 1
BlueSky
  • 139
  • 3
  • 9

1 Answers1

5

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!

evenodd
  • 2,026
  • 4
  • 26
  • 38
  • and if you are trying to use core graphics: http://stackoverflow.com/questions/1435544/measuring-the-pixel-width-of-a-string – evenodd Jul 26 '13 at 19:01