UIImage with smooth rounded corners in quartz

后端 未结 1 1085
渐次进展
渐次进展 2020-12-11 10:40

I am just testing the following code to round corners on UIImage:

- (UIImage *)makeRoundedImage:(UIImage *)image radius:(float)radius;
{
    CALayer *imageLa         


        
相关标签:
1条回答
  • 2020-12-11 11:15

    Here is UIImage category:

    - (UIImage *) imageWithRoundedCornersRadius: (float) radius
    {
        // Begin a new image that will be the new image with the rounded corners
        UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
    
        // Add a clip before drawing anything, in the shape of an rounded rect
        CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
        [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius] addClip];
    
        // Draw your image
        [self drawInRect:rect];
    
        // Get the image, here setting the UIImageView image
        UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
    
        // Lets forget about that we were drawing
        UIGraphicsEndImageContext();
    
        return roundedImage;
    }
    
    0 讨论(0)
提交回复
热议问题