I'm making a test app to see what it's like to use SwiftUI, and I want my test app to have a custom view which is a grid of perpendicular lines, with spacing specified as state variables.
However, I can't figure out how to do this in a UI system that seems to have no custom drawing methods.
import SwiftUI
struct GridBackgroundView : View {
@State var horizontalSpacing: CGFloat = 48
@State var verticalSpacing: CGFloat = 48
@State var anchor: Anchor<CGPoint>.Source = .center
var numberOfHorizontalGridLines: UInt {
return // Something?
}
var numberOfVerticalGridLines: UInt {
return // Something?
}
var body: some View {
Group {
ForEach(0 ... numberOfHorizontalGridLines) { _ in
// Something?
}
ForEach(0 ... numberOfVerticalGridLines) { _ in
// Something?
}
}
}
}
#if DEBUG
struct GridView_Previews : PreviewProvider {
static var previews: some View {
GridBackgroundView()
}
}
#endif
I don't know what to put in the // Something? areas. There's no line view built into SwiftUI, and I can't for the life of me find out what the width of the view is (possibly because that's not part of a View in SwiftUI?)


