码迷,mamicode.com
首页 > 其他好文 > 详细

UIScrollView 截图

时间:2015-10-19 18:59:36      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

- (IBAction) renderScrollViewToImage
    {
        UIImage* image = nil;

        UIGraphicsBeginImageContext(_scrollView.contentSize);
        {
            CGPoint savedContentOffset = _scrollView.contentOffset;
            CGRect savedFrame = _scrollView.frame;
        
            _scrollView.contentOffset = CGPointZero;
            _scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);
        
            [_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];        
            image = UIGraphicsGetImageFromCurrentImageContext();
            
            _scrollView.contentOffset = savedContentOffset;
            _scrollView.frame = savedFrame;
        }
        UIGraphicsEndImageContext();

        if (image != nil) {
            [UIImagePNGRepresentation(image) writeToFile: @"/tmp/test.png" atomically: YES];
            system("open /tmp/test.png");
        }
    }

UIScrollView 截图

标签:

原文地址:http://www.cnblogs.com/liudongyan/p/4892369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!