Line Break in Localizable.strings for MFMailComposeViewController
-
29-10-2019 - |
Frage
How can I add line breaks in my language file for use in MFMailComposeViewController
? The \n
doesent work for me. A break with a normal klick on return key has the same result, no line breaks!
My file:
"Body_eMail"= "Hello, here is some text.\n\nLorem ipsum alsu.\n\nAnd some text, more...";
I want:
Hello,
here is some text. Lorem ipsum alsu.
And some text, more...
This works fine for UILabel (as @lawicko mentioned below) but when adding to a MFMailComposeViewController
the \n
characters are displayed inline, like below:
Hello, here is some text.\n\nLorem ipsum alsu.\n\nAnd some text, more...
What is the right way?
Lösung
First ensure your MFMailComposeViewController
has isHTML:YES
set.
MFMailComposeViewController *emailView = [[MFMailComposeViewController alloc] init];
NSString *emailBody = NSLocalizedString(@"Email Body", @"");
[emailView setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:emailView animated:YES];
In your Localizable.strings
you must use the HTML <br />
tag to produce line breaks.
"emailBody" = "Hello, here is some text.<br /><br />Lorem ipsum alsu.<br /><br />And some text, more...";
Andere Tipps
Adding \n works if you display the text in the UITextView. It also works if you display the text in the UILabel if you set the appropriate numberOfLines. I just tested it on iOS5 simulator and iPod with iOS 5.0.1.