UIView截屏

碰到一个UIView截屏的需要,网上查了下,简单粗暴把代码记下来

- (UIImage *) captureScreen:(UIView*)view {

    CGRect rect = view.bounds;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

你可能感兴趣的:(ios学习)