自定义形状,

This commit is contained in:
2024-01-30 18:06:53 +08:00
parent 5109b242a6
commit 073ff4aa68
11 changed files with 194 additions and 153 deletions

View File

@@ -0,0 +1,43 @@
//
// TopRound.swift
// demo
//
// Created by Jason on 2024/1/30.
//
import SwiftUI
// ios16
struct TopRoundedRectangle: Shape {
let cornerRadius: Double
init(cornerRadius: Double = 0) {
self.cornerRadius = cornerRadius
}
func path(in rect: CGRect) -> Path {
Path { path in
path.move(to: CGPoint(x: rect.minX + cornerRadius, y: rect.minY))
path.addLine(to: CGPoint(x: rect.maxX - cornerRadius, y: rect.minY))
path.addArc(
center: CGPoint(x: rect.width - cornerRadius, y: cornerRadius),
radius: cornerRadius,
startAngle: Angle(degrees: -90),
endAngle: Angle(degrees: 0),
clockwise: false
)
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.minX, y: cornerRadius))
path.addArc(
center: CGPoint(x: cornerRadius, y: cornerRadius),
radius: cornerRadius,
startAngle: Angle(degrees: 180),
endAngle: Angle(degrees: 270),
clockwise: false
)
}
}
}