4

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?

Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
webschnecke
  • 919
  • 1
  • 8
  • 21

2 Answers2

6

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

Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
2

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.

lawicko
  • 7,246
  • 3
  • 37
  • 49
  • Hi, the text is shown in an e-mail (no uilabel etc...)... to recommend the app... the \n doesnt work... ;-( – webschnecke Feb 24 '12 at 09:49
  • Do you use MFMailComposeViewController to send your emails? – lawicko Feb 24 '12 at 11:16
  • Yes I do ;-)-(void)displayMailComposerSheet { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:NSLocalizedString(@"Betr",@"Bet")]; // Set up recipients //NSArray *toRecipients = [NSArray arrayWithObject:@""]; //[picker setToRecipients:toRecipients]; NSString *emailSharing = NSLocalizedString(@"Bdy",@"Txt"); // Fill out the email body text [picker setMessageBody:emailSharing isHTML:YES]; [self presentModalViewController:picker animated:YES]; [picker release];} – webschnecke Feb 26 '12 at 21:30
  • Sometimes `numberOfLines` is not enough - some set phrases which look bad when are split into different lines – Vyachaslav Gerchicov Jan 12 '16 at 15:00