mugunthan
mugunthan

Reputation: 77

IOS insert line break to data retrieved from parse.com

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

Answers (3)

myknack
myknack

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

Albara
Albara

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

Julian
Julian

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

Related Questions