0
votes

I am using UIActivityViewController for email, facebook, twitter and sms sharing..

I have successfully shared image as well text.

But, now i want to share UIView. I wanted to know is it possible or not?

If yes please let me know how.

Thanks in advance.

2
Share UIView? What do you mean? - Larme

2 Answers

0
votes

You can have a UIImage from a UIView,

Here is what you should be using if you are only supporting iOS7+:

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0f);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
    UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return snapshotImage;
}

Otherwise use this:

#import <QuartzCore/QuartzCore.h>

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}
0
votes

You can take a screenshot of a UIView object. See please following topic:

How to capture UIView to UIImage without loss of quality on retina display

I have successfully shared image as well text.

After getting UIImage from UIView, you can share appropriate image.