1

I have a label which displays a string triggered by a button and some int values entered in some textfields...

However, how can I make the label's string to be in multiple lines?

I can see a lot of people have asked this question, but for some reason, when I try to follow the answers it deletes the rest of my sentence after the use of "\n", as I have just tried earlier...

Frederic
  • 497
  • 2
  • 9
  • 22

2 Answers2

4

If the label is created in storyboard, go to your storyboard and select it, then in the attribute inspector there is a field 'Lines' with default value of 1. change that 0 and that should work.

enter image description here

Lukas
  • 3,423
  • 2
  • 14
  • 26
2

Try using the following code

var label:UILabel = UILabel(frame: CGRectMake(10
    ,100, 300, 40));
label.textAlignment = NSTextAlignment.Center;
label.numberOfLines = 0;
label.font = UIFont.systemFontOfSize(16.0);
label.text = "First label\nsecond line";

Also make sure the height of label is enough to handle the string when presented in multiline else it won't show the next line in label.

To calculate height of label according to String this link can be helpful

Community
  • 1
  • 1
Piyush Sharma
  • 1,891
  • 16
  • 23
  • If I use your code, it does not respond at all when I hit my button. it just displays the string my page starts with. – Frederic Oct 27 '15 at 23:07
  • you added this label in you view as self.view.addSubview(label); also update the frame of this label as per your requirement. – Piyush Sharma Oct 27 '15 at 23:10