14

Is there anyway of making a UILabel wrap to the next line or do I have to use a UITextView?

TheLearner
  • 18,967
  • 35
  • 92
  • 162

2 Answers2

20

You would need to set the numberOfLines property to 0 and explicitly specify its dimensions, either in IB or programmatically. However, if you have a lot of text to display, I would recommend using a UITextView.

Evan Mulawski
  • 51,888
  • 11
  • 110
  • 142
  • 5
    set `numberOfLines` to `0`, and the `UILabel` will be filled with text, limited by width and height. it will not create new lines and automatically extend the width/height. the width/height must be explicity set to accomodate for the size of text – james Jan 07 '11 at 22:19
  • 1
    To adjust the size of the label dynamically, please see my answer and this post: http://stackoverflow.com/a/8796896/662605 – Daniel Oct 10 '12 at 19:00
  • Also gotta set the lineBreakMode property on the UILabel to NSLineBreakMode.ByWordWrapping in Swift and UILineBreakModeWordWrap in Objective-C – C0D3 Apr 22 '15 at 21:08
  • What do you mean explicitly specify its dimensions with IB? Can I just set the width in the view or do I need to specify something else also? – Tyler Hilbert Mar 02 '17 at 17:27
1

What you want is to adjust your label according to the content's size.

In iOS 6, AutoLayout will work a charm, you should set the label to have numberOfLines = 0

In a non AutoLayout scenario, you will also want to make sure the frame of your UILabel is adjusted to show the content that's on the next line.

Please check out this answer and sample code for that: https://stackoverflow.com/a/8796896/662605

Community
  • 1
  • 1
Daniel
  • 22,521
  • 12
  • 107
  • 150