我的应用程序使用UIView
,我想通过电子邮件发送此图纸。这可能吗?
答案 0 :(得分:6)
将其转换为图像并将该图像作为附件邮寄。
+ (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];
}
答案 1 :(得分:3)
只有将其转换为图像才能执行此操作。
转换为图片
您必须首先链接QuartzCore框架以及#import <QuartzCore/QuartzCore.h>
接下来插入代码:
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
来源:http://iphonedevelopment.blogspot.com/2008/10/getting-contents-of-uiview-as-uiimage.html
以电子邮件形式发送
您可以使用MFMailComposeViewController类,这样您就不必离开应用程序了。本教程帮助我:
要添加图像,您可以使用同一个类的方法:addAttachmentData:mimeType:fileName:,它接受三个参数。查看Apple文档以获取更多信息。