limon
limon

Reputation: 3212

Elegant way to deal UILabel text alignment ?

I'm developing an app in iOS 6 and using Xcode 4.5.2.

I have a simple UIView which contains some text according to localizable string. Well, according to displayed language, the number of lines of the text is changing.For exemple, in English, there is two lines, but in Turkish, it takes just one line.

I'm also supposed to center text alignment. Well, right now i'm able to accomplish it, but i'm using two different UILabel and i've set their text manually. So, it doesn't work if i change the displayed language of the text Simple image

So,

1- What is the best way to handle this kind of alignment issue ?

2- Suppose that i use UILabel, well how can i make a new line to be able to have the output as shown in the pic. None of the line breaking mode seems to work. Same question if i use UITextView?

Thanks in advance

Upvotes: 1

Views: 2135

Answers (2)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39998

Do these thing

  1. Set your number of line to 0.
  2. Make your text alignment centre.
  3. Insert \n character in you string where you want line break.
  4. Make sure to set the width of your UILabel.

By default when text reaches the width of the lablel it moves to next line but what you want that before it reaches to it's width it should move to next line which is not possible by setting the properties of UILabel. For that you have to set new line character in your string.

Upvotes: 1

jhilgert00
jhilgert00

Reputation: 5489

Have you tried using the UILabel Instance method textRectForBounds:limitedToNumberOfLines:

From the documentation:

The value 0 indicates there is no maximum number of lines and that the rectangle should encompass all of the text.

Upvotes: 0

Related Questions