是否可以通过电子邮件发送UIView?(Is it possible to send a UIView by e

编程入门 行业动态 更新时间:2024-10-24 22:21:14
是否可以通过电子邮件发送UIView?(Is it possible to send a UIView by e-mail? [closed])

我的应用程序使用UIView ,我想通过电子邮件发送此绘图。 这可能吗?

My application draws on a UIView, and I want to send this drawing by e-mail. Is this possible?

最满意答案

将其转换为图像并将该图像作为附件邮寄。

+ (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } -(void)displayComposerSheet { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@"Check out this image!"]; // Set up recipients // NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; // NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; // NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; // [picker setToRecipients:toRecipients]; // [picker setCcRecipients:ccRecipients]; // [picker setBccRecipients:bccRecipients]; // Attach an image to the email UIImage *coolImage = ...; NSData *myData = UIImagePNGRepresentation(coolImage); [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"coolImage.png"]; // Fill out the email body text NSString *emailBody = @"My cool image is attached"; [picker setMessageBody:emailBody isHTML:NO]; [self presentModalViewController:picker animated:YES]; [picker release]; }

Convert it into an image and mail that image as an attachment.

+ (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } -(void)displayComposerSheet { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@"Check out this image!"]; // Set up recipients // NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; // NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; // NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; // [picker setToRecipients:toRecipients]; // [picker setCcRecipients:ccRecipients]; // [picker setBccRecipients:bccRecipients]; // Attach an image to the email UIImage *coolImage = ...; NSData *myData = UIImagePNGRepresentation(coolImage); [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"coolImage.png"]; // Fill out the email body text NSString *emailBody = @"My cool image is attached"; [picker setMessageBody:emailBody isHTML:NO]; [self presentModalViewController:picker animated:YES]; [picker release]; }

更多推荐

本文发布于:2023-08-07 03:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461208.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以通过   电子邮件   send   UIView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!