How to mask a square image into an image with round corners in iOS?

前端 未结 8 1685
[愿得一人]
[愿得一人] 2020-11-28 01:20

How can you mask a square image into an image with round corners?

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 01:53

    I use this method.

    + (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size;
        {
          UIImage *img = nil;
    
    
            CGRect rect = CGRectMake(0, 0, size.width, size.height);
            UIGraphicsBeginImageContext(rect.size);
            CGContextRef context = UIGraphicsGetCurrentContext();
            CGContextSetFillColorWithColor(context,
                                         color.CGColor);
            CGContextFillRect(context, rect);
            img = UIGraphicsGetImageFromCurrentImageContext();
    
            UIGraphicsEndImageContext();
    
    
          return img;
        }
    

提交回复
热议问题