根据指定frame,截取View的某个部分

2018-11-16  本文已影响0人  hie

//view:需要截取的视图

//rect:截取的范围

- (UIImage *)imageFromView: (UIView *)view atFrame:(CGRect)rect{

    UIGraphicsBeginImageContext(view.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    UIRectClip(rect);

    [view.layer renderInContext:context];

    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return  theImage;

}

上一篇 下一篇

猜你喜欢

热点阅读