Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As we cant use sizeWithAttributes for all iOS greater than 4.3 we have to write conditional code for 7.0 and previous iOS.</p> <p><strong>1) Solution 1:</strong> </p> <pre><code>if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { CGSize size = CGSizeMake(230,9999); CGRect textRect = [specialityObj.name boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14]} context:nil]; total_height = total_height + textRect.size.height; } else { CGSize maximumLabelSize = CGSizeMake(230,9999); expectedLabelSize = [specialityObj.name sizeWithFont:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; //iOS 6 and previous. total_height = total_height + expectedLabelSize.height; } </code></pre> <p><strong>2) Solution 2</strong></p> <pre><code>UILabel *gettingSizeLabel = [[UILabel alloc] init]; gettingSizeLabel.font = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16]; // Your Font-style whatever you want to use. gettingSizeLabel.text = @"YOUR TEXT HERE"; gettingSizeLabel.numberOfLines = 0; CGSize maximumLabelSize = CGSizeMake(310, 9999); // this width will be as per your requirement CGSize expectedSize = [gettingSizeLabel sizeThatFits:maximumLabelSize]; </code></pre> <p><strong>The first solution is sometime fail to return proper value of height. so use another solution. which will work perfectly.</strong></p> <p>The second option is quite well and working smoothly in all iOS without conditional code. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload