iOS截屏分享二维码(UIView)

来源:互联网 发布:3306端口是干嘛的 编辑:程序博客网 时间:2024/05/17 03:05

二维码图片
而分享的是uiview
本来准备用view转image来做的,有点烦,就用截屏来做了,

CGSize size = _backView.bounds.size;    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);    //rect是以_backView来作为基础的;250是截取后图片的尺寸    CGRect rec = CGRectMake(0, 0, 250, 250);    [_backView drawViewHierarchyInRect:rec afterScreenUpdates:YES];    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    _currentImage = image;    NSData * data = UIImagePNGRepresentation(image);    //将截取的图片存入文件夹内    _filePath = [FileUtil getFilePath:@"二维码.png"];    [data writeToFile:_filePath atomically:YES];

然后通过UIDocumentInteractionController分享出去就行了

_con = [[UIDocumentInteractionController alloc] init];        _con.URL = [NSURL fileURLWithPath:_filePath];        [_con presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];

*注意截取后的二维码图片的宽高比例必须和原来一致,否则读不出来。

0 0