본문 바로가기
iOS

원하는 View를 이미지로 캡처 하기

by 냥이있는삶 2020. 5. 18.
반응형
- (UIImage *)imageFromView:(UIView *)view 
{
    if(UIGraphicsBeginImageContextWithOptions != NULL) 
    {
        UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0); 
    } else { 
        UIGraphicsBeginImageContext(view.frame.size); 
    }

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return image; 
}
반응형