我正在为 UILabel
赋值。如果我从 NSManagedObject
中获取值,则\n 会按原样显示并且不会将其作为新行读取。
这是我的代码
let cards:Card = cardArray[0] as! Card
lblTitle?.text = cards.title
//Output in UiLabel is "This is \n title"
我希望 UiLabel 将\n 读取为新行
但是下面的代码给出了预期的输出
lblTitle?.text = "This is \n title"
最佳答案
我认为您 title
包含转义字符,即 \n
正在打印的原因 尝试将 \\n
替换为 \n
。
swift 3
lblTitle?.text = cards.title.replacingOccurrences(of: "\\n", with: "\n")
Swifr 2.3 或更低版本
lblTitle?.text = cards.title.stringByReplacingOccurrencesOfString("\\n", withString: "\n")
关于ios - 在 UILabel 中读取\n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39858442/