Search code examples
iphoneobjective-cuilabelframesizetofit

Change the size of UILabel or the font to fit in Accented Character


I have a UILabel with Text inside it called :

self.textLabel; 

Now, I noticed that whenever I added an accented letter like Ä Ö Ü, then I get an effect like :

enter image description here

Notice how the top dots on the accented letters are cut off. I want to get the text to fit the label, however the self.textLabel.numberOfLines = 2 constraint which ensures that I have 2 lines and the text after the sentence goes beyond the width is maintained. Essentially, I want a label like :

enter image description here

With the dots maintained. Now, I have tried :

[self.frame sizeToFit] which does not work because it wraps around the entire text. As I said, cut the text out after 2 lines.

Using .bounds and CGRectMake to create new frames and then assign their new height to the current frame, which doesn't work either. Check out https://stackoverflow.com/questions/21948714/adjust-size-of-uilabel-to-fit-height-of-text for more information. Can someone please help me out with this?


Solution

  • The answer was to do

    self.textLabel.numberOfLines = 2;
    

    And then doing :

    [self.textLabel sizeToFit];