image.layer.cornerRadius = 8;
image.layer.masksToBounds = YES;
重写drawRect,(-_-,要弄个新的属性才会走这里,本菜鸟还不懂啊,先弄了个UIImageView用它自己的image走都不走这里。。。图形这方面设计太少了)
//注意背景色要和cell的背景色设置一致哦,不然-0-
- (void)drawRect:(CGRect)rect {
CGRect bounds = self.bounds;
[[UIColor whiteColor]set];
UIRectFill(bounds);
[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:8.0] addClip];
[self.image drawInRect:bounds];
}
- (void)setImage:(UIImage *)image {
_image = image;
//需要这一步,需要刷新,不然显示会出问题
[self setNeedsDisplay];
}
- (void)dealloc {
self.image = nil;
}
- (UIImage *)imageByComposingImage:(UIImage *)image withMaskImage:(UIImage *)maskImage {
CGImageRef maskImageRef = maskImage.CGImage;
CGImageRef maskRef = CGImageMaskCreate(CGImageGetWidth(maskImageRef),
CGImageGetHeight(maskImageRef),
CGImageGetBitsPerComponent(maskImageRef),
CGImageGetBitsPerPixel(maskImageRef),
CGImageGetBytesPerRow(maskImageRef),
CGImageGetDataProvider(maskImageRef), NULL, false);
CGImageRef newImageRef = CGImageCreateWithMask(image.CGImage, maskRef);
CGImageRelease(maskRef);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
return newImage;
}