Dipti Y W
Dipti Y W

Reputation: 474

Entering line breaks in NSString

I need to set mail Body in MFMailComposeViewController to separate some text in number of lines. I am using the following line of code but it isn't working.

[mail setMessageBody:[NSString stringWithFormat:@"Hi I am Interested to buy a vehicle for me Name :%@ %@ \n Contact No. : %@ \n Email : %@\n",txtFirst.text, txtLast.text, txtContact.text, txtEmail.text ] isHTML:YES];

also i tried this

[mail setMessageBody:[NSString stringWithFormat:@"Hi I am Interested to buy a vehicle for me Name :%@ %@ </br> Contact No. : %@ </br> Email : %@</br>",txtFirst.text, txtLast.text, txtContact.text, txtEmail.text ] isHTML:YES];

is there any solution to do it.

Upvotes: 7

Views: 7740

Answers (3)

foebe
foebe

Reputation: 359

If you have isHTML set to YES in your message, use <br/> to do a line break, if isHTML is NO, use \r\n.

Upvotes: 6

Pascal Bayer
Pascal Bayer

Reputation: 2613

Your messageBody is set to HTML what will mean that you need to add </ br> for line break, or set isHTML:NO

Upvotes: 2

raaz
raaz

Reputation: 12500

Try this

[mail setMessageBody:
[NSString stringWithFormat:@"First:%@
                           \r\n Second:%@
                           \r\n Third:%@
                           \r\n Fourth:%@",
txtFirst.text, txtSecond.text, txtThird.text, txtFourth.text ] isHTML:YES];

Upvotes: 11

Related Questions