Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic UILabel truncating the text
    primarykey
    data
    text
    <p>I'm using code provided in <a href="https://stackoverflow.com/questions/9181368/ios-dynamic-sizing-labels">this answer</a> to create a dynamic label and it works for the most part. But whenever the label text goes over 94 characters in length it gets truncated and ellipsis' are added. </p> <p>There is one more odd thing about this is that if I add more characters to the string they are shown but the last 2 lines are still truncated.</p> <p>Eg.</p> <p>The string:</p> <pre><code>this is a very very long string with lots of words to test the dynamic bubble sizing one two three. </code></pre> <p>shows up like this:</p> <pre><code>this is a very very long string with lots of words to test the dynamic bubble sizing one tw... </code></pre> <p>But when I double the string by using the same sentence again in the label it show more of te text but still truncates it.</p> <p>Eg.</p> <p>The string:</p> <pre><code>this is a very very long string with lots of words to test the dynamic bubble sizing one two three. this is a very very long string with lots of words to test the dynamic bubble sizing one two three. </code></pre> <p>shows like this:</p> <pre><code>this is a very very long string with lots of words to test the dynamic bubble sizing one two three. this is a very very long string with lots of words to tes... </code></pre> <p>Here's the code I'm using.</p> <pre><code>NSString *temp = [NSString stringWithFormat:@"this is a very very long string with lots of words to test the dynamic bubble sizing one two three"]; captionLabel.text = temp; //Calculate the expected size based on the font and linebreak mode of your label CGSize maximumLabelSize = CGSizeMake(296,9999); CGSize expectedLabelSize = [temp sizeWithFont:captionLabel.font constrainedToSize:maximumLabelSize lineBreakMode:captionLabel.lineBreakMode]; //adjust the label the the new height. CGRect newFrame = captionLabel.frame; newFrame.size.height = expectedLabelSize.height; captionLabel.frame = newFrame; </code></pre> <p>Hope someone has an idea because this has me scratching my head.</p> <p><strong>EDIT</strong></p> <p>Using captionLabel.frame.size.width instead of hard-coded 296 fixed it, thanks to @troolee, if he/she chooses to create an answer I will mark it correct.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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