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?

有帮助吗?

解决方案

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...";

enter image description here

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top