はじめに
SwiftUIの標準機能では点線の区切り線が実装できなかったので、カスタムで作成してみました。
実装
struct Line: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: rect.width, y: 0))
return path
}
}
使い方
struct ContentView: View {
var body: some View {
Line()
.stroke(style: .init(dash: [4, 3]))
.foregroundColor(.black)
.frame(height: 0.5)
}
}
おわり
いい感じにできました