Search code examples
iphoneobjective-cnsstringplistproperty-list

Use line breaks of retrieved NSString


I retrieve an NSString from a Property list and display it in a UILabel. The NSString already includes \n s, however the UILabel just displays them as text. How can I tell the UILabel to actually use the \n s as line breaks?


Solution

  • Everything you type into a plist in the plist editor is interpreted as plain text. Try it... put a ' into a field and right click -> view as "plain text" and you'll see it substitutes it for '. Therefore you can't put \n into a plist because it thinks you're just typing text and will treat it as such. Instead of putting \n into your plist use Alt+Enter to get your newline. If you view this as a text file now you'll see \ns printed and new lines acctually shown in the text file.

    Now when you output it it won't display \n it will just give it a new line.

    Plus, as has been mentioned UITextField is only one line anyway and you probably would benefit from using UITextView.