🖼️GridLines
SwiftUI ⟩ Drawing ⟩ Shape ⟩ Helper Shapes ⟩

⬆️ 需要: GridLinesShape
// 2022.02.10
import SwiftUI
/// vertical & horizontal grid lines in a rect.
/// ```
/// GridLines()
/// GridLines(rows: 5, cols: 5)
/// GridLines(color: .gray, border: .pink)
/// ```
struct GridLines: View {
    
    var rows: Int = 10
    var cols: Int = 10
    var color: Color = .secondary.opacity(0.5)    // grid line color
    var border: Color = .primary.opacity(0.8)     // border color
    
    var body: some View {
        GridLinesShape(rows: rows, cols: cols)    // 💜 GridLinesShape
            .stroke(color)
            .border(border)
    }
}⬆️ 需要: .white()
struct GridLines_Previews: PreviewProvider {
    static var previews: some View {
        HStack {
            GridLines()
                .padding(8)
                .background(.black)
            GridLines(color: .white(0.3), border: .white(0.1))
                .padding(8)
                .background(.white(0.4))    // 🌀ShapeStyle+ .white()
                .border(.black)
            GridLines(rows: 5, cols: 5, color: .orange, border: .pink)
                .padding(8)
                .background(.white(0))
        }
        .padding()
        .frame(height: 200)
    }
}- uses GridLinesShape. 
- used in Point's previews. 
- used in Vehicle.CarBodyShape's previews. 
Last updated
Was this helpful?