作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 MFMailComposeViewController 发送电子邮件,
使用此代码我可以获得图像,但图像位于文本详细信息之后,我不需要第一个图像和之后的文本,
这是我的代码,
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Setting up the Subject, recipients, and message body.
[mail setToRecipients:[NSArray arrayWithObjects:Emailid,nil]];
[mail setSubject:@"Receipt"];
NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"Gift.png"], 1);
[mail addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];
[mail setMessageBody:@"Receipt" isHTML:NO];
NSString *emailBody;
emailBody = [NSString stringWithFormat:@
"<br>Purchase Amount: </br> " "$ %@"
"<br>Amount Received: </br> " "$ %@"
"<br>Change: </br> " "$ %@"
,AmountData,txtAmount.text,ChangeAmount.text];
[mail setMessageBody:emailBody isHTML:YES];
请有人建议我我该怎么做?
最佳答案
据我所知,这是 mfmailcomposeviewcontroller 的默认行为,而不是仅仅将图像添加为附件,您可以按如下方式首先显示图像以创建正文部分
(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];
}
这显示了here
关于iphone - 如何在电子邮件正文中的某些文本之后设置第一个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10069158/
我是一名优秀的程序员,十分优秀!