0

我正在尝试创建一个包裹在形状中的弯曲路径以附加到标签栏,但我无法获得所需的外观。在此处输入图像描述 这是我想要的外观。关于如何创建这种形状的任何想法?

4

1 回答 1

2

我能够通过使用自定义路径并将其附加到选项卡栏来回答我自己的问题。

struct Arc: Shape {
    
    var height: CGFloat = 20
    var length: CGFloat = 80
    var startX: CGFloat = 0
    
    func path(in rect: CGRect) -> Path {
        var path = Path()
        let midPoint: CGFloat = (startX + length) / 2
        let apex1: CGFloat = (startX + midPoint) / 2
        let apex2: CGFloat = (midPoint + length) / 2
        
        path.move(to: CGPoint(x: startX, y: height))
        
        path.addCurve(to: CGPoint(x: midPoint, y: 0), control1: CGPoint(x: apex1, y:
            height), control2: CGPoint(x: apex1, y: 0))
        
        path.addCurve(to: CGPoint(x: startX + length, y: height), control1: CGPoint(x: apex2, y: 0), control2: CGPoint(x: apex2, y: height))
        
        
        return path
    }
}
于 2020-05-03T01:14:21.087 回答