SwiftUI中的曲线和路径

时间:2020-05-02 19:01:28

标签: swiftui shapes uibezierpath tabbar swiftui-layout

我正在尝试创建一条弯曲的路径,该路径包裹在一个形状中以便附加到标签栏,但是在获得理想的外观时遇到了麻烦。 enter image description here 这是我要的外观。关于如何创建此形状的任何想法?

1 个答案:

答案 0 :(得分:0)

我可以通过使用自定义路径并将其附加到标签栏来回答自己的问题。

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: length, y: height), control1: CGPoint(x: apex2, y: 0), control2: CGPoint(x: apex2, y: height))


        return path
    }
}