Muhammad Usman Piracha Muhammad Usman Piracha - 1 year ago 118
iOS Question

Reading \n in UiLabel

I am assigning value to

. If I get value from
than \n shows as it is and doesn't read it as new line.
Here is my code

let cards:Card = cardArray[0] as! Card
lblTitle?.text = cards.title
//Output in UiLabel is "This is \n title"

I want UiLabel to read \n as new line

However below code gives expected output

lblTitle?.text = "This is \n title"

Answer Source

I think you title contains escaped character i.e the reason \n is printing try once replacing \\n with \n.

Swift 3

lblTitle?.text = cards.title.replacingOccurrences(of: "\\n", with: "\n")

Swifr 2.3 or lower

lblTitle?.text = cards.title.stringByReplacingOccurrencesOfString("\\n", withString: "\n")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download