Search code examples
iphoneiosipad

How to add line feed to body text on MFMailComposeViewController


I am using a MFMailComposeViewController to create a new email.

On the body text I want something like this:

Hi,

This application bla bla bla.

To make this work you have to bla bla.

Thanks.

So, we have four paragraphs of text and I want to give a space between them.

I am constructing the body text string like this:

NSString *body = @"Hi,\n\nThis application bla bla bla.\n\nTo make this work you have to bla boa.\n\nThanks\n\n";

Hoping \n would add a space between paragraphs.

I know I can make it work if I use <br />, making the email be HTML, but I want to create a plain text email for maximum compatibility.

How do I do that?


Solution

  • Make sure you have made isHTML:NO in the below method. With isHTML:NO, \n should work fine.

    NSString *body = @"Hi,\n\nThis application bla bla bla.\n\nTo make this work you have to bla boa.\n\nThanks\n\n";
    [mailComposer setMessageBody:body isHTML:NO];
    

    Output:

    Hi,

    This application bla bla bla.

    To make this work you have to bla bla.

    Thanks.