内存的消耗最少渲染快速切圆角

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 30)];

//    image.image = [UIImage imageNamed:@"newfeatures0"];

image.backgroundColor = [UIColor redColor];

[self.view addSubview:image];

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:image.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(8, 8)];

CAShapeLayer *layer = [[CAShapeLayer alloc] init];

layer.path = maskPath.CGPath;

image.layer.mask = layer;

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:image.bounds];

[maskPath appendPath:[UIBezierPath bezierPathWithRoundedRect:image.bounds cornerRadius:10]];

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];

shapeLayer.path = maskPath.CGPath;

//    shapeLayer.frame = image.bounds;

shapeLayer.fillColor = [UIColor whiteColor].CGColor;

shapeLayer.fillRule = kCAFillRuleEvenOdd;

[image.layer addSublayer:shapeLayer];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容