Can I send a UIView by email?

My application relies on UIView , and I want to send this picture by email. Is it possible?

+4
source share
2 answers

Convert it to an image and send this 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]; } 
+6
source

You can only do this if you convert it to an image.

Convert to Image

You must first bind the QuartzCore structure as well as #import <QuartzCore/QuartzCore.h>

Then enter the code:

 UIGraphicsBeginImageContext(myView.bounds.size); [myView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

source: http://iphonedevelopment.blogspot.com/2008/10/getting-contents-of-uiview-as-uiimage.html

Send as Email

You can use the MFMailComposeViewController class, so you do not need to leave the application. This lesson helped me:

http://iphonedevsdk.com/forum/tutorial-discussion/43633-quick-tutorial-how-add-mfmailcomposeviewcontroller.html

To add an image, you can use the same class method: addAttachmentData: mimeType: fileName:, which takes three parameters. See Apple docs for more information.

+3
source

Source: https://habr.com/ru/post/1446489/


All Articles