NSString *message = @"Can be a short string or a very long string";
CGSize rowSize = [message sizeWithFont:[UIFont fontWithName:@"Helvetica" size:16.0] constrainedToSize:CGSizeMake(250, 1000) lineBreakMode:UILineBreakModeWordWrap];
CGSize rowSizeBold = [message sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] constrainedToSize:CGSizeMake(250, 1000) lineBreakMode:UILineBreakModeWordWrap];
(rowSize.height and rowSizeBold.height are always equal) – this wasn’t right – thx to jaydee3
the returned height is wrong and clips the text.
Any ideas?
solution: (works for Helvetica, Helvetica-Bold and any other font)
Reducing the width of the rowSize by the margin (15) returns the right height for UITextField.
NSString *message = @"Can be a short string or a very long string";
CGSize rowSize = [message sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] constrainedToSize:CGSizeMake(235, 1000) lineBreakMode:UILineBreakModeWordWrap];
UITextField *messageTextView.frame = CGRectMake(60, 10, 250, rowSize.height);
thx to Ganzolo!
If you are using UITextField to display font, you’d probably get this wrong result because UITextField has margin.
So in your constrained size you should remove the margin of the UITextField on the width component.