美文网首页
根据指定frame,截取View的某个部分

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

作者: hie | 来源:发表于2018-11-16 11:28 被阅读0次

//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;

}

相关文章

网友评论

      本文标题:根据指定frame,截取View的某个部分

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