How to set first Image after Some Text in Email body?

风格不统一 提交于 2019-12-06 07:58:53

as of my knowledge this is the default behavior of the mfmailcomposeviewcontroller instead of just adding image as attachment you can do as below to show image first just to create body part

(void)createEmail {


NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
   [emailBody appendString:@"<p>Some email body text can go here</p>"];
   UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
   NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];

   NSString *base64String = [imageData base64EncodedString];
  [emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
  [emailBody appendString:@"</body></html>"];
    NSLog(@"%@",emailBody);

 //mail composer window
    MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
    emailDialog.mailComposeDelegate = self;
    [emailDialog setSubject:@"My Inline Image Document"];
    [emailDialog setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:emailDialog animated:YES];
    [emailDialog release];
    [emailBody release];
}

this is shown here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!