Skip to content

Instantly share code, notes, and snippets.

@JayachandraA
Last active October 17, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayachandraA/56e4d0ad0fb0eab2332786afd99b64dd to your computer and use it in GitHub Desktop.
Save JayachandraA/56e4d0ad0fb0eab2332786afd99b64dd to your computer and use it in GitHub Desktop.
Swift: Core Graphics custom drawing
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