UIImage with transparent rounded corners

后端 未结 5 2095
无人共我
无人共我 2020-12-03 15:50

I\'m using following code to add rounded corners to my UIImage, but the problem is that the rounded corners are showing \"white\" area instead of transparent or \"clear\". W

5条回答
  •  眼角桃花
    2020-12-03 16:53

    lukya's comment below your question is what you probably want to do.

    Make sure you import QuartzCore:

    #import 
    

    Then, if you have a UIImageView of your image that you want to have rounded corners, just call (assuming imageView is a property and cornerRadius is the desired corner radius):

    self.imageView.layer.cornerRadius = cornerRadius;
    self.imageView.clipsToBounds = YES;
    

    Since you already have self.CGImage, you could do this to create a UIImageView:

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:self.CGImage]];
    

    Just make sure to release the imageView after you add it as a subview.

提交回复
热议问题