先截取tableview,然后再拼一张图片,分享到微信(省略)
// 截取区域图片大小
- (UIImage *)snapshotViewImage
{UIImage* image = nil;/*参数size为新创建的位图上下文的大小缩放因子,实际上设为0后,系统就会自动设置正确的比例了。opaque — 透明开关,如果图形完全不用透明,设置为YES以优化位图的存储*/UIGraphicsBeginImageContextWithOptions(self.ljGoodsSourceListASTableView.view.contentSize, YES, 0.0);//保存tableview当前的偏移量CGPoint savedContentOffset = self.ljGoodsSourceListASTableView.view.contentOffset;CGRect saveFrame = self.ljGoodsSourceListASTableView.frame;//将collectionView的偏移量设置为(0,0)self.ljTableView.contentOffset = CGPointZero;self.ljTableView.frame = CGRectMake(0, 0, self.ljTableView.contentSize.width, self.lljTableView.contentSize.height);//在当前上下文中渲染出collectionView[self.ljTableView.layer renderInContext: UIGraphicsGetCurrentContext()];//截取当前上下文生成Imageimage = UIGraphicsGetImageFromCurrentImageContext();//恢复collectionView的偏移量self.ljTableView.contentOffset = savedContentOffset;self.ljTableView.frame = saveFrame;UIGraphicsEndImageContext();return image;
}// 拼接两张图片
- (UIImage *)composeTopImage:(UIImage *)topImage bottomImage:(UIImage *)bottomImage
{//1.创建上下文尺寸CGSize size = CGSizeMake(kDEVICEWIDTH, topImage.size.height +bottomImage.size.height);UIGraphicsBeginImageContextWithOptions(size, YES, 0.0);//2.先把topImage 画到上下文中[topImage drawInRect:CGRectMake(0, 0, topImage.size.width, topImage.size.height)];//3.再把小图放在上下文中[bottomImage drawInRect:CGRectMake(0, topImage.size.height, kDEVICEWIDTH, 140)];UIImage *resultImg = UIGraphicsGetImageFromCurrentImageContext();//从当前上下文中获得最终图片UIGraphicsEndImageContext();//关闭上下文return resultImg;
}// 截取图片
- (UIImage *)captureImages
{// 第一张图片UIImage *shareImage1 = [self snapshotViewImage];// 拼接后图片(第二张)UIImage *shareImage2 = [self composeTopImage:shareImage1 bottomImage:@"image_selected"];// 图片转换//NSData *shareImage3 = UIImagePNGRepresentation(shareImage2);return shareImage2;
}#pragma mark -- 跳转到另外一个页面展示出来
- (void)jumpClick:(id)sender
{UIImage *_llImage = [self captureImages];LJViewController *_ljVc = [[LJViewController alloc]init];_ljVc.ljimage = _llImage;[self.navigationController pushViewController:_ljVc animated:YES];
}