0

This is the code:

NSString *labelString = @"Username: \n some text";
NSMutableAttributedString *labelAttributedString = [[NSMutableAttributedString alloc]initWithString:labelString];
...
self.smartLabel.attributedText = labelAttributedString;

The label is:

Username: some text

Instead of:

Username:
some text 

Edit: The label has enough space to put the text in 1 line, still I want to insert the breakline (programatically!)

Luda
  • 7,282
  • 12
  • 79
  • 139
  • does your label has multiple lines? – Wali Haider Feb 24 '14 at 09:59
  • it doesn't matter how much space you have in a one line. If you need a line break you must enable your label to have multiple lines by setting it's `numberOfLines` property to 0 or a higher value than 1. – Rukshan Feb 24 '14 at 11:29
  • If the text is long, the line is breaked correctly. Didn't have to set numberOfLines to 0. – Luda Feb 24 '14 at 13:01

2 Answers2

2

It looks like your label has only one line to display increase your label line to two or more than two as shown in given image. enter image description here

****Edite**:Since your label is OHAtrributedLabel so you can do the same by code given below**

self.smartLabel.numberOfLines = 0;

self.smartLabel.lineBreakMode = NSLineBreakByWordWrapping

Wali Haider
  • 1,202
  • 1
  • 16
  • 23
0

Add this line

self.smartLabel.numberOfLines = 0;

and if needed,

self.smartLabel.lineBreakMode = NSLineBreakByWordWrapping
Rukshan
  • 7,902
  • 6
  • 43
  • 61