简体   繁体   English

UIBezierPath - 添加圆角

[英]UIBezierPath - Add rounded corner

I am using a UIBezierPath to draw a curved line. 我正在使用UIBezierPath绘制一条曲线。 The curve works however, I am unable to curve the edges of the line. 然而,曲线有效,我无法弯曲线的边缘。

在此输入图像描述

If you look at the top/bottom end of the curve, you can see that the edges are flattened out, thats not what I want. 如果你看一下曲线的顶端/底端,你可以看到边缘是扁平的,这不是我想要的。 Is there a way to curve the edges? 有没有办法弯曲边缘?

I am using a simple UIBezierPath to draw an (almost) semi circle. 我使用一个简单的UIBezierPath绘制(几乎)半圆。 This creates the curved line shape that I want: 这创建了我想要的曲线形状:

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];

Despite setting the cornerRadius property, the corners are not curved. 尽管设置了cornerRadius属性,但角落不会弯曲。 What am I doing wrong? 我究竟做错了什么?

Thanks for your time, Dan. 谢谢你的时间,丹。

Include the following. 包括以下这些。

circle.lineCap = kCALineJoinRound;

For Swift 3.0 and above 适用于Swift 3.0及以上版本

circle.lineCapStyle = .Round;

Swift 4.0 Swift 4.0

circle.lineCap = kCALineCapRound

and if you want your lines intersections to also be rounded set 如果你想让你的线条交叉也是圆角设置

circle.lineJoin = kCALineCapRound

as well. 同样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM