The following is supposed to create an isometric lattice pattern across a UIView, but all it does is turn the page black:
class IsometricGrid: UIView {
let gridSpacing: CGFloat = 20
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.setStrokeColor(UIColor.black.cgColor)
context?.setAlpha(0.2)
context?.setLineWidth(100)
for x in stride(from: 0, through: self.frame.width, by: gridSpacing) {
for y in stride(from: 0, through: self.frame.height, by: gridSpacing) {
// Draw the diagonal lines for the isometric grid
context?.move(to: CGPoint(x: x, y: y))
context?.addLine(to: CGPoint(x: x + gridSpacing, y: y + gridSpacing))
context?.strokePath()
context?.move(to: CGPoint(x: x + gridSpacing, y: y))
context?.addLine(to: CGPoint(x: x, y: y + gridSpacing))
context?.strokePath()
}
}
}
}
let isometricGridView = IsometricGrid()
isometricGridView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
view.addSubview(isometricGridView)
I am using an older version of Swift, but this is CoreGraphics and nothing new. Perhaps it is the iPhone XR emulator ?