macOS SwiftUI教程之绘制垂直虚线Dash(教程含源码)
2023-09-11 14:18:32 时间
实战需求
macOS SwiftUI教程之绘制垂直虚线Dash
本文价值与收获
看完本文后,您将能够作出下面的界面
看完本文您将掌握的技能
- 1、 移动原点位置.move(to: CGPoint(x: 0, y: 0));
- 2、绘制线段.addLine(to: CGPoint(x: rect.width, y: rect.height));
- 3、设置边框类型.stroke(style: StrokeStyle(lineWidth: 1, dash: [2]));
- 4、设置高度和宽度.frame(width: 1, height: 100)。
实战代码
import SwiftUI
struct ContentView: View {
var body: some View {
VStack{
Text("SwiftUI 垂直虚线")
TestDottedLineView()
}.frame(minWidth:600,minHeight: 400)
}
}
struct DottedLine: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: 0