<分区>
我的应用程序绘制了一个 UIView
,我想通过电子邮件发送这个绘图。这可能吗?
<分区>
我的应用程序绘制了一个 UIView
,我想通过电子邮件发送这个绘图。这可能吗?
最佳答案
将其转换为图像并将该图像作为附件发送。
+ (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];
}
关于objective-c - 是否可以通过电子邮件发送 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13420219/