分享界面图片,将自定义视图控件转换成图片方法

之前项目需求是分享某个页面的图片,要分享的图片上会加二维码的图片。
其实是自定义要分享的界面,该界面某个位置加上对应二维码图片。
之后将UI控件转换成图片,再分享出去。

//控件转换图片的方法
- (void)setupShareView {

    //self.shareView 是你自定义的分享界面
    UIGraphicsBeginImageContextWithOptions(self.shareView.bounds.size, NO, 0.0);
    [self.shareView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image3=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageViewData = UIImageJPEGRepresentation(image3, 0.6);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pictureName= @"screenHelp.png";
    //分享的图片沙盒路径
    _savedImagePath = [documentsDirectory stringByAppendingPathComponent:pictureName];
    NSLog(@"%@",_savedImagePath);
    [imageViewData writeToFile:_savedImagePath atomically:YES];

    //调用分享方法
    [self shareSucBtnClick];
}

  //调用shareSDK分享,
- (void)shareSucBtnClick{
     NSString *shareStr = CustomLocalizedString(@"shareWeiboyuemapaobuText", nil);
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];

    //取_savedImagePath 沙盒图片路径
    [shareParams SSDKSetupShareParamsByText:shareStr
                                     images:_savedImagePath
                                        url:[NSURL URLWithString:@""]
                                      title:@""
                                       type:SSDKContentTypeImage];
    [ShareSDK showShareActionSheet:self.view
                             items:nil
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
               }];
}

你可能感兴趣的:(分享界面图片,将自定义视图控件转换成图片方法)