Search code examples
iphoneobjective-ctextuiviewlandscape

How to have one view support portrait and landscape


I have one view in my app that has a lot of writing on it.

It's important that this writing stay in the "one lines" that it is.

The problem is sometimes each line changes length causing the text to scale down in size.

So how would I make this view also supporg landscape?


Solution

  • You have three choices :

    1) Let the text span more than one line

    2) Truncate the text instead of scaling it

    3) Accept that the text is going to scale.

    You've already said in your question that you don't want (1) or (3) so you need to do option (2).

    You can turn off text scaling by setting this on your label :

    myLabel.adjustsFontSizeToFitWidth = NO;
    

    and choose how you want the text to be trucated, for example this :

    myLabel.lineBreakMode.UILineBreakModeMiddleTruncation;
    

    will trim from the center of your label i.e. 'This_is_..._text' - it adds the ... for you instead of scaling the text.