I made a 3x3 cell layout with UIViews. So there are 9 UIViews!!!
I am trying to screenshot these 9 UIviews individually. But Whatever I tried, I can only screenshot the 1st UIview.
HEre is the screenshot of the main view that holds the 9 subviews:
And I want to screenshot the second tile by sending _tile2, but the final result I get is _tile1 only.
Here is the code:
[self saveImage:[self screenshotTile:_tile2]]; //_tile1,_tile2...._tile9 gave the same result
What I believe is If I send the _tile1, it should screenshot the _tile1 area on the self.view, and If I send the _tile2, it should screenshot the _tile2 area on the self.view .But whatever I send, it only captures the _tile1 area on the view.
-(void)saveImage:(UIImage *)img{
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
-(UIImage *)screenshotTile :(UIView *)imgV{
UIGraphicsBeginImageContext(imgV.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
_tileImg1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return _tileImg1;
}
I tried this solution which suggests to shift the image after taking the screenshot, but it didnt work too:
UIGraphicsBeginImageContext(sshot.frame.size);
[sourceImage drawAtPoint:CGPointMake(-50, -100)]; // I tried -imgV.frame.origin.v, -imgV.frame.origin.y but it didnt work for me!!!