I need to add a line break to a string, which I obtain from the plist. The string is passed to the UILabel
to presented on screen.
For example, my text is like "Adding a line break to a string from plist in iOS"
I need a line break after the word break.
I have added a "\n"
, hence the text became "Adding a line break \n to a string from plist in iOS". Ensured the numberoflines = 0
for the UILabel
.
But I can't see the line break and the text "\n"
appears in the text itself.
Need some guidance on this.. Thanks..
EDIT:
[photo setCaption:[NSString stringWithFormat:@"%@",[[galleryArray objectAtIndex:index] objectForKey:@"Title"]]];
The plist file requires an actual newline character in the string value. You can't enter the two characters \ and n
. Those are only treated as a newline character by the compiler.
Bring up the plist file in Xcode and edit the string value. To enter a newline, press option-Return
on your keyboard instead of just Return
.
Now when you load this string value into an NSString
in your app, the newline will be part of the string value. And when set at the text of a label, the newline will appear (assuming the label is setup to show multiple lines).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With