Reputation: 77
i am trying to retrieve some string data from parse.com and i've added "\n, \n & \r" into the data, but it still does not give me the line breaks, how do format the line below to get line breaks.
self.label.text = [NSString stringWithFormat:@"%@", [object objectForKey:@"ParseStringDate"]];
Upvotes: 0
Views: 177
Reputation: 81
if some has the same challenge in swift - please find attached a short string extension:
extension String {
func formatStringFromParseWithLineBreaks() -> String {
let sourceString: String = self
let resultString = sourceString.stringByReplacingOccurrencesOfString("\\n", withString: "\n")
return resultString
}
}
It is easy to use:
let stringFromParse = "Great\\nExample"
let newString = stringFromParse.formatStringFromParseWithLineBreaks()
Have fun
Upvotes: 1
Reputation: 1296
self.label.text = [NSString stringWithFormat:@"first\n%@\n another", [object objectForKey:@"ParseStringDate"]];
Make sure you have numberOfLines
of the label set to 0. This should work.
Upvotes: 0
Reputation: 9337
if you get the text that should be presented in multiple lines then you should try to set for your label this property:
self.label.numberOfLines = 0;
it basically means that label can be multiline, make sure that frame of that label is sufficient to show more that one line of text
Upvotes: 1