chenzq12

/**

 *  图片裁剪成圆形(无边框)

 */

- (UIImage *)imageWithCornerRadius:(CGFloat)radius {

    

    CGFloat sideLength = MAX(self.size.width, self.size.height);

    CGRect rect = (CGRect){0.f, 0.f, sideLength, sideLength};

    

    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

    CGContextAddPath(UIGraphicsGetCurrentContext(),

                     [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:sideLength * 0.5].CGPath);

    CGContextClip(UIGraphicsGetCurrentContext());

    

    CGFloat imgX = (sideLength - self.size.width) * 0.5;

    CGFloat imgY = (sideLength - self.size.height) * 0.5;

    CGRect imgRect = (CGRect){imgX, imgY, self.size};

    

    [self drawInRect:imgRect];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    

    UIGraphicsEndImageContext();

    return image;

}

分类:

技术点:

相关文章:

  • 2022-01-23
  • 2021-11-22
  • 2021-09-08
  • 2021-11-17
  • 2021-11-17
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2021-12-29
  • 2021-11-17
  • 2021-11-14
  • 2021-12-29
  • 2022-01-12
相关资源
相似解决方案