iOS 截取tableView, scrollerView图片
CGPoint currentOffset = self.storeTable.contentOffset;
CGRect currentFrame =self.storeTable.frame;
self.storeTable.contentOffset = CGPointZero;
// 2. 将 scrollView 展开为其实际内容的大小
self.storeTable.frame=CGRectMake(0,0,self.storeTable.contentSize.width, 3*325);
// 3. 第三个参数设置为 0 表示设置为屏幕的默认缩放因子
UIGraphicsBeginImageContextWithOptions(CGSizeMake(SCREEN_WIDTH, 3 * 325), YES, 0);
self.storeTable.layer.backgroundColor = [UIColor whiteColor].CGColor;
[self.storeTable.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 保存到相册
UIImageWriteToSavedPhotosAlbum(snapshotImage, nil, nil, nil);
// 4. 重新设置 scrollView 的偏移和位置,还原现场
self.storeTable.contentOffset= currentOffset;
self.storeTable.frame= currentFrame;
网友评论