objective-c - 是否可以通过电子邮件发送 UIView?

标签 objective-c ios email uiview drawing

<分区>

我的应用程序绘制了一个 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/

相关文章:

python - Python 的 os.system() 相当于 cocoa/Objective-C 的什么?

ios - iOS 推送通知是否需要苹果开发者计划成员(member)资格

ios - 尝试将 maximumValue 设置为 UISlider 时应用程序崩溃

PHP Foreach 用于从数据库发送电子邮件?

c# - 如何调整电子邮件中嵌入图像的大小

html - HTML 电子邮件中的间距

ios - 处理 iOS 8 键盘扩展中的返回键

iphone - 从 IOS 应用程序获取 facebook 相册

ios - UIPageViewController 第一次没有预加载

ios - 如何使我的 SLComposeViewController 可用于服务类型 (Facebook) iOS swift