ios - 将曲线添加到 UIBezierPath(arcCentre) 的末端

标签 ios swift

我在 UIView 的 drawRect 函数中添加了以下代码,创建了以下附加的绿色弧线。

有没有办法让曲线末端的边缘看起来像所附较小图像中的红色圆弧圆边。

[![//Draw the Interior
        let center = CGPoint(x: bounds.width/2,
            y: bounds.height/2)

        //Calculate the radius based on the max dimension of the view.
        let radius = max(bounds.width, bounds.height)

        //Thickness of the Arc
        let arcWidth: CGFloat = 76

        //Start and End of Circle angle
        let startAngle: CGFloat = 3 * π/4
        let endAngle: CGFloat = π/4

        let path = UIBezierPath(arcCenter: center, radius: radius/2 - arcWidth/2,
            startAngle: startAngle,
            endAngle: endAngle,
            clockwise: true)

        path.lineWidth  = arcWidth
        counterColor.setStroke()
        path.stroke()]

enter image description here enter image description here

最佳答案

设置lineCapStyle贝塞尔路径的属性 .Round:

A line with a rounded end. Quartz draws the line to extend beyond the endpoint of the path. The line ends with a semicircular arc with a radius of 1/2 the line’s width, centered on the endpoint.

path.lineCapStyle = .Round

关于ios - 将曲线添加到 UIBezierPath(arcCentre) 的末端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276463/

相关文章:

ios - 在 iOS 上使用共享横幅切换标签时显示 AdMob 和/或 iAd

iphone - NSFileManager 多实例写入原子性

ios - 如何从 UIButton 中隐藏 UITableView

ios - 如何为导航栏制作 CAGradientLayer 动画

ios - 使用iOS处理/缩小高分辨率图像

ios - 应用程序未在设备中自动启动并在 xcode 上出现错误

ios - 在 iOS 上,如何将一组常见样式应用于 UILabels,而不必为每个最后一个样式进行子类化?

ios - 一旦所有项目出现在 View Controller 中,就关闭 UIAlertView

ios - 我的 firebase int 返回 nil

swift - 旋转时 CALayers 转换不正确