是否可以通过电子邮件发送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]; }更多推荐
发布评论