円を描く
extension CGRect { init(_ center:CGPoint, _ size:CGSize) { self.origin = CGPoint(x:center.x - size.width/2, y:center.y - size.height/2) self.size = size } } extension CGPoint { init(_ x:CGFloat, _ y:CGFloat) { self.x = x self.y = y } } extension CGSize { init(_ width:CGFloat, _ height:CGFloat) { self.width = width self.height = height } } class RDView:UIView { func drawCircle(context:CGContext) { context.setLineWidth(20) context.strokeEllipse(in: CGRect(CGPoint(100,100), CGSize(100,100))) context.setFillColor(red: 1.0, green: 1.0, blue: 0.3, alpha: 0.3) context.setStrokeColor(red: 1.0, green: 0.3, blue: 0.5, alpha: 0.3) context.strokeEllipse(in: CGRect(x: 100, y: 100, width: 100, height: 100)) context.fillEllipse(in: CGRect(x:120, y:120, width:60, height:60)) } override func draw(_ rect: CGRect) { // Drawing code let p = UIGraphicsGetCurrentContext() drawCircle(context: p!) } }
上のextensionは簡便のため。