Last active
October 17, 2019 11:13
-
-
Save JayachandraA/56e4d0ad0fb0eab2332786afd99b64dd to your computer and use it in GitHub Desktop.
Swift: Core Graphics custom drawing
This file contains hidden or 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
class ZigZagCardView: UIView { | |
override func awakeFromNib() { | |
layer.cornerRadius = 5 | |
layer.masksToBounds = true | |
backgroundColor = UIColor.clear | |
} | |
override func draw(_ rect: CGRect) { | |
super.draw(rect) | |
let noOfZigs = 25 | |
let path = UIBezierPath() | |
let y = rect.size.height - 10 | |
path.move(to: CGPoint(x: 0, y: 0)) | |
path.addLine(to: CGPoint(x: 0, y: y)) | |
path.addLine(to: CGPoint(x: 0, y: y)) | |
let equalZig: Int = Int(rect.width/25) | |
for i in 1...noOfZigs { | |
path.addLine(to: CGPoint(x: CGFloat(equalZig*i), y: y-10)) | |
path.addLine(to: CGPoint(x: CGFloat(equalZig*i)+10, y: y)) | |
if i == noOfZigs{ | |
path.addLine(to: CGPoint(x: rect.width, y: 0)) | |
} | |
} | |
path.lineWidth = 10 | |
path.close() | |
UIColor.white.setFill() | |
UIColor.white.setStroke() | |
path.lineWidth = 10 | |
path.stroke() | |
path.fill() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment