Adding line breaks in iOS alert messages using Objective-C

EarlGrey picture EarlGrey · Nov 10, 2011 · Viewed 15.2k times · Source

A noob question.

I have an alert:

"alertMessage" = "This is my message:    1  2  3.  And another one: 5 6 7";

which I am displaying with:

NSString *asd = NSLocalizedString (@"alertMessage", @"");
NSString *alertTitle = NSLocalizedString (@"alertTitle", @"");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle message:asd delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

How do I implement line breaks so "And Another one:" starts on the second line.

thank you!

Answer

David Dunham picture David Dunham · Nov 10, 2011

Add line break characters (\n) to your message.