指定视图超屏幕范围截图,如:UITextView、UIScrollView、UITableView、UICollectionView等包含contentOffSize
属性的视图。
如下示例:
/// 屏幕截图(指定视图)
- (UIImage *)screenImageWithView:(UITextView *)view
{
UIGraphicsBeginImageContextWithOptions(view.contentSize, NO, 0.0);
//
CGPoint savedContentOffset = view.contentOffset;
CGRect savedFrame = view.frame;
view.frame = CGRectMake(0 , 0, view.contentSize.width, view.contentSize.height);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
view.contentOffset = savedContentOffset;
view.frame = savedFrame;
//
UIGraphicsEndImageContext();
//
return image;
}