从相册或拍照获得头像

2019PHP高薪工程师学习路线图....>>>

 //开启上下文
    UIGraphicsBeginImageContext(self.bounds.size);
    //获取上下文
    CGContextRef ctx =  UIGraphicsGetCurrentContext();
    //渲染
    [self.layer renderInContext:ctx];
    //获取截图
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    //关闭上下文
    UIGraphicsEndImageContext();
    //获取截图范围
    CGRect rect =  _iconFrame.frame;
    CGRect cutrect = CGRectMake(rect.origin.x+20, rect.origin.y+20, rect.size.width-40, rect.size.height-40);
    UIImage *cutImg = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(img.CGImage, cutrect)];
    //block
    _photoBlock(cutImg);