-
Notifications
You must be signed in to change notification settings - Fork 3
iOS Drawing
Kevin Leong edited this page Dec 2, 2016
·
2 revisions
The code below draws a circle with a vertical line down the center.
import UIKit
@IBDesignable
class PushButtonView: UIButton {
override func draw(_ rect: CGRect) {
// Circle
let path = UIBezierPath(ovalIn: rect)
UIColor.red.setFill()
path.fill()
// Vertical Line
let linePath = UIBezierPath()
let lineLength = bounds.width * 0.8
// Position cursor at a CGPoint
linePath.move(to: CGPoint(x: bounds.width/2.0, y: bounds.height/2.0 - lineLength/2.0))
// Draw line to a CGPoint
linePath.addLine(to: CGPoint(x: bounds.width/2.0, y: bounds.height/2.0 + lineLength/2.0))
// Configure stroke and draw
linePath.lineWidth = 3.0
UIColor.white.setStroke()
linePath.stroke()
}
}
- Apple Developer *Layer
- UIView vs CALayer - Stack Overflow
- Views vs Layers - Rapture in Venice