普通view截图
1 | + (UIImage *)gjj_viewScreenShot:(UIView *)view { |
tableView、collectionView等scrollView生成长截图
实现步骤
- 保存scrollView截取前的偏移量及Frame
- 计算出你要截取的长图的高度及宽度,即scrollView的contentSize,将scrollView.frame设成scrollView.contentSize
- 渲染出scrollView整体(上下文),截取当前scrollView生成Image
- 恢复scrollView的偏移量及Frame
1 | + (UIImage *)gjj_scrollViewScreenShot:(UIScrollView *)scrollView { |
webView生成长截图
webView和scrollView的截图大同小异
1 | + (UIImage *)gjj_webViewScreenShot:(UIWebView *)webView { |
图片拼接
很多需求是截图附带二维码等进行分享。
1 | + (UIImage *)gjj_addHeadImage:(UIImage *)headImage footImage:(UIImage *)footImage toMasterImage:(UIImage *)masterImage { |
添加水印
1 | + (UIImage *)gjj_addWaterImage:(UIImage *)waterImage toMasterImage:(UIImage *)masterImage waterImageRect:(CGRect)rect { |