UITextView 文字換行
阿新 • • 發佈:2019-01-05
I need to indicated a 'new line' in a string in an XML file I'm loading.
If I hard code the string:
myTextView.text =[NSString stringWithString:@"Line1 \nLine2 \nLine3"];
It displays:Line1Line2Line3
(as expected)
But if I put the exact string in my XML file:
<someNodestring="Line1 \nLine2 \nLine3"And then load it into the UITableView it displays:
Line1\nLine2 \nLine3
原因是從XML中讀取出來的"\n",系統認為是字串,會預設轉換為"\\n",所以當顯示的時候就是字串了,要想顯示換行,需要自己手動將"\\n"轉換為"\n",這樣才能換行.
NSString*b =[a stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];