绘制 UIView 四边形圆

Drawing UIView Quad Circle

如何像上面那样制作 UIView。

在下面尝试过,但它创建了一个半圆形类型的视图。

let circlePath = UIBezierPath(arcCenter: CGPoint(x: topView.bounds.size.width, y: topView.bounds.size.height / 2), radius: topView.bounds.size.height, startAngle: .pi, endAngle: 0.0, clockwise: false)
let circleShape = CAShapeLayer()
circleShape.path = circlePath.cgPath
topView.layer.mask = circleShape

一个圆有2 * .pi弧度,你从pi到0,就是一个半圆。您的开始角和结束角必须相差 0.5 pi。

自己画。没有什么复杂的。

带样本:

  • 从中心点开始
  • 转到 BottomPoint(行)
  • 从 BottomPoint 到 LeftPoint 的弧度,角度为 Pi/2 到 Pi(顺时针方向)
  • 转到左点
  • 转到中心点(线)

UIBezierPath:

let bezierPath = UIBezierPath()
let centerPoint = CGPoint(x: view.bounds.width, y: 0)
let bottomPoint = CGPoint(x: view.bounds.width, y: view.bounds.height)
let leftPoint = CGPoint(x: 0, y: 0)
bezierPath.move(to: bottomPoint) //not needed
bezierPath.addArc(withCenter: centerPoint,
                  radius: view.bounds.height,
                  startAngle: CGFloat.pi/2.0,
                  endAngle: CGFloat.pi,
                  clockwise: true)
bezierPath.addLine(to: leftPoint) //not needed
bezierPath.addLine(to: centerPoint)

有两个“不需要”,因为它们是隐含的,但如果它们对您来说“隐藏太多”,您可能想要写下它们。

为什么是你自己?因为,一个圆圈只有两个点并在它之间填充。换句话说,它不会去“centerPoint”去填充它。 我在手工路径中使用的相同角度的示例: