โฌ๏ธ ้่ฆ๏ผ floating +โโจรท int, path.line(), Rectangular
// 2022.02.10
import SwiftUI
/// vertical & horizontal grid lines in a rect.
/// ```
/// GridLinesShape(rows: 3, cols: 3)
/// GridLinesShape(rows: 3) // 3x10 grids
/// GridLinesShape() // 10x10 grids
/// ```
struct GridLinesShape: Shape {
var rows: Int = 10
var cols: Int = 10
func path(in rect: CGRect) -> Path {
Path { path in
// horizontal lines
for i in 1..<rows {
let y: CGFloat = 1.0 / rows * i // ๐Int+
path.line(rect[0,y], rect[1,y]) // ๐Path+, ๐
ฟ๏ธ Rectangular
}
// vertical lines
for i in 1..<cols {
let x: CGFloat = 1.0 / cols * i
path.line(rect[x,0], rect[x,1])
}
}
}
}
struct GridLinesShape_Previews: PreviewProvider {
static var previews: some View {
HStack {
GridLinesShape(rows: 3, cols: 5).stroke()
GridLinesShape(rows: 3).stroke()
GridLinesShape().stroke()
}
.frame(height: 150)
.padding()
}
}