Last active
February 14, 2017 10:32
-
-
Save krooked/1caf46f5ae290b5d20aa2b1624970dd0 to your computer and use it in GitHub Desktop.
Draw circle with UKit in Xcode playground
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import PlaygroundSupport | |
func drawCircle(x: CGFloat, y: CGFloat) { | |
let p = UIBezierPath(ovalIn: CGRect(x: x, y: y, width: 10, height: 10)) | |
UIColor.blue.setFill() | |
p.fill() | |
} | |
UIGraphicsBeginImageContextWithOptions(CGSize(width: 200, height: 200), false, 0) | |
// Draw circle | |
for i in stride(from: 0, to: 200, by: 10) { | |
drawCircle(x: CGFloat(i), y: CGFloat(i)) | |
} | |
let im = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0)) | |
containerView.addSubview(UIImageView(image: im)) | |
PlaygroundPage.current.liveView = containerView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment