Created
July 19, 2017 11:34
-
-
Save NikhilManapure/bb42028e296a793c76083773ca18e532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBDesignable class GridView: UIView { | |
var numberOfColumns: Int = 2 | |
var numberOfRows: Int = 2 | |
var lineWidth: CGFloat = 1.0 | |
var lineColor: UIColor = UIColor.white | |
override func draw(_ rect: CGRect) { | |
if let context = UIGraphicsGetCurrentContext() { | |
context.setLineWidth(lineWidth) | |
context.setStrokeColor(UIColor.white.cgColor) | |
let columnWidth = Int(rect.width) / (numberOfColumns + 1) | |
for i in 1...numberOfColumns { | |
var startPoint = CGPoint.zero | |
var endPoint = CGPoint.zero | |
startPoint.x = CGFloat(columnWidth * i) | |
startPoint.y = 0.0 | |
endPoint.x = startPoint.x | |
endPoint.y = frame.size.height | |
context.move(to: CGPoint(x: startPoint.x, y: startPoint.y)) | |
context.addLine(to: CGPoint(x: endPoint.x, y: endPoint.y)) | |
context.strokePath() | |
} | |
let rowHeight = Int(rect.height) / (numberOfRows + 1) | |
for j in 1...numberOfRows { | |
var startPoint = CGPoint.zero | |
var endPoint = CGPoint.zero | |
startPoint.x = 0.0 | |
startPoint.y = CGFloat(rowHeight * j) | |
endPoint.x = frame.size.width | |
endPoint.y = startPoint.y | |
context.move(to: CGPoint(x: startPoint.x, y: startPoint.y)) | |
context.addLine(to: CGPoint(x: endPoint.x, y: endPoint.y)) | |
context.strokePath() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment