Reputation: 81
I've an image view
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
which I want to screenshot. The code I have is taking the whole screen. I've looked at the other answers on here and still can't work it out as I don't want to designate a size, I just need the whole of the image view as a screenshot.
- (UIImage*)captureView:(UIView *)view
{
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Upvotes: 0
Views: 113
Reputation: 5186
Replace the line
CGRect rect = [[UIScreen mainScreen] bounds];
with
CGRect rect = view.bounds;
Hope this will work as you want.
Upvotes: 2