Search code examples
iosxcodemfmailcomposeviewcontrollerline-breakslocalizable.strings

Line Break in Localizable.strings for MFMailComposeViewController


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?


Solution

  • 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