扫码关注官方订阅号
UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(40, 40, 40, 40)];
这样绘制一个圆之后怎么才能把圆之外的给去掉呢?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
CGFloat shorterSide = MIN(view.bounds.size.width, view.bounds.size.height); view.layer.cornerRadius = shorterSide / 2.0f;
试试calayer吧
通过直接设置cornerRadius,IOS会进行离屏渲染,会十分耗费CPU资源,这在UITableView中会出现界面卡顿的情况。你的思路是对的,就是通过UIBezierPath画一个圆,然后创建CAShapeLayer,CAShaperLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = bezierPath.CGPath; xxView.mask = maskLayer; 这样就是一个圆了
CAShaperLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = bezierPath.CGPath; xxView.mask = maskLayer;
UIView clipsTobounds CALayer masksToBounds
如果是让UIView变成圆形的 建议写一个UIView的分类
(void)HL_makeCircle {
self.layer.cornerRadius = MIN(self.bounds.size.width, self.bounds.size.height)/2; self.layer.masksToBounds = YES; }
如果只是想把view变成圆的话,楼上就是答案,如果绘制的话可以试试CGContextRef
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
试试calayer吧
通过直接设置cornerRadius,IOS会进行离屏渲染,会十分耗费CPU资源,这在UITableView中会出现界面卡顿的情况。你的思路是对的,就是通过UIBezierPath画一个圆,然后创建CAShapeLayer,
CAShaperLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = bezierPath.CGPath; xxView.mask = maskLayer;这样就是一个圆了
UIView clipsTobounds
CALayer masksToBounds
如果是让UIView变成圆形的 建议写一个UIView的分类
(void)HL_makeCircle {
self.layer.cornerRadius = MIN(self.bounds.size.width, self.bounds.size.height)/2;
self.layer.masksToBounds = YES;
}
如果只是想把view变成圆的话,楼上就是答案,如果绘制的话可以试试CGContextRef
self.layer.cornerRadius = radius;
self.layer.masksToBounds = YES;
}
radius设置成view width的0.5