美文网首页
UITableView Screenshort

UITableView Screenshort

作者: Alienchang | 来源:发表于2017-04-28 14:02 被阅读24次
    - (UIImage *)screenshort{
        UIImage* viewImage = nil;
        
        UIGraphicsBeginImageContextWithOptions(self.contentSize, self.opaque, 0.0);
        {
            CGPoint savedContentOffset = self.contentOffset;
            CGRect savedFrame = self.frame;
            
            UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentSize.width, self.contentSize.height)];
            UIView *tempSuperView = self.superview;
            
            [self removeFromSuperview];
            [tempView addSubview:self];
            
            self.contentOffset = CGPointZero;
            self.frame = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
            [self.layer renderInContext: UIGraphicsGetCurrentContext()];
            
            viewImage = UIGraphicsGetImageFromCurrentImageContext();
            
            [self removeFromSuperview];
            
            [tempSuperView addSubview:self];
            self.contentOffset = savedContentOffset;
            self.frame = savedFrame;
        }
        UIGraphicsEndImageContext();
        
        return viewImage;
    }
    

    相关文章

      网友评论

          本文标题:UITableView Screenshort

          本文链接:https://www.haomeiwen.com/subject/gnbhwttx.html