Question

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?

Was it helpful?

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.

OTHER TIPS

Well, first, you are going to need a string that you can modify. To accomplish that, you can simply do:

NSMutableString* correctedPath = [path mutableCopy];

At that point, you can use -insertString:atIndex: to insert any characters you need.

You're using the wrong class here.

UITextField doesn't (for all that I know) support multi-line input. For that, you will need a UITextView (it has editing enabled by default). It should interpret \n's without any problems. It also has a lineBreakMode property, if you want to make use of that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top