UIBezierPath的使用方法
UIBezierPath的使用方式:
一,直接添加轨迹,然后stroke或者fill
UIColor *blue =[UIColor blueColor];
[blue set];
UIBezierPath *bezier =[UIBezierPath bezierPath];
bezier.lineWidth=2;
bezier.lineCapStyle=kCGLineCapRound;
bezier.lineJoinStyle=kCGLineJoinRound;
[bezier moveToPoint:CGPointMake(50, 5)];
[bezier addLineToPoint:CGPointMake(90, 25)];
[bezier addLineToPoint:CGPointMake(75, 50)];
[bezier addLineToPoint:CGPointMake(25, 50)];
[bezier closePath];
[bezier fill];
二,创建UIBezierPath对象,并将去path添加到layer上面
UIBezierPath *bezier2 =[UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50) radius:20 startAngle:0 endAngle:M_PI clockwise:YES];
CAShapeLayer *layer =[CAShapeLayer layer];
layer.path=bezier2.CGPath;
layer.strokeColor=[UIColor redColor].CGColor;
layer.fillColor=[UIColor blueColor].CGColor;
layer.borderWidth=1;
[self.layer addSublayer:layer];
1 2 3 4 5 6 7 8 9 10 11 12 13 | //1.创建一个红色View let view = UIView ( frame : CGRect ( x : 0 , y : 0 , width : 200 , height : 200 )) view . backgroundColor = . red //2.创建一个图层 let maskLayer = CAShapeLayer () //创建一个贝塞尔曲线 let path = UIBezierPath ( ovalIn : view . bounds ) //将贝塞尔曲线的path设置到图层的path上 maskLayer . path = path . cgPath //3.设置遮罩图层 view . layer . mask = maskLayer |
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了