IOS SDK - how to screen shot content of tableView?

后端 未结 3 1388
情书的邮戳
情书的邮戳 2020-12-30 08:47

How to screen-shot ALL content of tableView? (all content = visible are + NOT visible area)

I tried this:

UIGraphicsBeginImageContext(self.tableView.         


        
相关标签:
3条回答
  • 2020-12-30 08:58
    + (UIImage *)captureView:(UIScrollView *)view inContentRect:(CGRect)rect{
        UIImage* image = nil;
    
        CGPoint savedContentOffset = view.contentOffset;
        CGRect savedFrame = view.frame;
    
        UIGraphicsBeginImageContextWithOptions(view.contentSize, 1, 0);
        view.contentOffset = CGPointZero;
        view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height);
    
        [view.layer renderInContext: UIGraphicsGetCurrentContext()];
        image = UIGraphicsGetImageFromCurrentImageContext();
    
        view.contentOffset = savedContentOffset;
        view.frame = savedFrame;
    
        UIGraphicsEndImageContext();
    
        // after all of this, crop image to needed size
        return [Utils cropImage:image toRect:rect];                                 
    }
    
    0 讨论(0)
  • 2020-12-30 08:58

    You have to use contentSize.height for getting the height of tableview

    Try this

    UIGraphicsBeginImageContext(self.tableView.contentSize.height);
    [self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    self.imageView.image = image1;
    
    0 讨论(0)
  • 2020-12-30 09:05

    Yes, you can do this. I can't provide the working code for what you want, I can just guide you how to do this. In the loop you have to get renders of all parts of the table by changing it's contentOffset and place each image in the array. After you got all the portions of the table view, you have to connect the parts of the table in to one image (draw each image in cgimagecontext, remember to set correct size for the result image). That's it, it's not that hard :) Hope this helps, Good luck!

    0 讨论(0)
提交回复
热议问题