ios - UIBezierPath - 添加圆角

标签 ios objective-c uibezierpath rounded-corners cashapelayer

我正在使用 UIBezierPath 绘制一条曲线。但是曲线有效,我无法弯曲线的边缘。

enter image description here

如果您查看曲线的顶端/底端,您会发现边缘变平了,这不是我想要的。有没有办法使边缘弯曲?

我正在使用一个简单的 UIBezierPath 来绘制一个(几乎)半圆。这创建了我想要的曲线形状:

CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0) radius:70 startAngle:1.0472 endAngle:5.23599 clockwise:NO].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor colorWithWhite:1.0 alpha:0.2].CGColor;
circle.lineWidth = 18.0;
circle.cornerRadius = 10.0;
circle.position = CGPointMake(100, 100);
circle.anchorPoint = CGPointMake(0.5, 0.5);
[mainView.layer addSublayer:circle];

尽管设置了 cornerRadius 属性,但角不是弯曲的。我做错了什么?

谢谢你抽出时间,丹。

最佳答案

包括以下内容。

circle.lineCap = kCALineJoinRound;

对于 Swift 3.0 及以上版本

circle.lineCapStyle = .Round;

关于ios - UIBezierPath - 添加圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42223186/

相关文章:

ios - 兄弟 NSManagedObjectContext 如何交互?

objective-c - 异步加载和更改图像

ios - 不显示图像

objective-c - 尽管已设置操作,但单击分段时仍显示 NSSegmentedControl 菜单

objective-c - 如果代码包含在函数中的花括号中会发生什么?

objective-c - 制作图片跳转IOS

ios - 当移动网络浏览器使用自定义 URL 启动 native iOS 应用程序时,会传递哪些元数据?

swift - 在 Swift 中添加到 View 后如何更改 UIBezierPath 的颜色?

ios - 使用现有路径为 UIView 创建掩码?

ios - 向 UIBezierPath 动态添加值