0
Follow
2
View

Swftui custom shape

du7775 注册会员
2023-01-26 11:59

YES! I managed to write the correct form! If anyone needs it, here's the code

struct CustomShape: Shape {
    
    let radius: CGFloat = 14.0
    
    private let padding: CGFloat = 31.5
    
    func path(in rect: CGRect) -> Path {
        
        var path = Path()
        
        path.move(to: .zero)
        
        path.addLine(to: CGPoint(x: rect.midX - padding - radius, y: rect.minY))
        
        path.addQuadCurve(to: CGPoint(x: rect.midX - padding, y: rect.minY + radius),
                          control: CGPoint(x: rect.midX - padding, y: rect.minY))
        
        path.addLine(to: CGPoint(x: rect.midX - padding,
                                 y: rect.minY + padding - radius))
        
        path.addQuadCurve(to: CGPoint(x: rect.midX - padding + radius,
                                      y: rect.minY + padding),
                          control: CGPoint(x: rect.midX - padding,
                                           y: rect.minY + padding))
        

        path.addLine(to: CGPoint(x: rect.midX + padding - radius,
                                 y: rect.minY + padding))
        
        
        path.addQuadCurve(to: CGPoint(x: rect.midX + padding,
                                      y: rect.minY + padding - radius),
                          control: CGPoint(x: rect.midX + padding, y: rect.minY + padding))
        
        path.addLine(to: CGPoint(x: rect.midX + padding,
                                 y: rect.minY + radius))
                
        path.addQuadCurve(to: CGPoint(x: rect.midX + padding + radius, y: rect.minY),
                          control: CGPoint(x: rect.midX + padding, y: rect.minY))
        
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))
    

        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
        path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
        
        return path
    }
    
}

About the Author

Question Info

Publish Time
2023-01-26 11:59
Update Time
2023-01-26 11:59