Skip to content

Instantly share code, notes, and snippets.

@funkyboy
Last active May 3, 2016 01:16
Show Gist options
  • Select an option

  • Save funkyboy/9c7e3e06bea0625cb9b0e643e5498af2 to your computer and use it in GitHub Desktop.

Select an option

Save funkyboy/9c7e3e06bea0625cb9b0e643e5498af2 to your computer and use it in GitHub Desktop.
Circle view that progressively fills its border
import UIKit
import XCPlayground
let viewWidth: CGFloat = 300
var end: CGFloat = 0
let lineWidth: CGFloat = 20
let circleView = UIView(frame: CGRectMake(0, 0, viewWidth, viewWidth))
XCPlaygroundPage.currentPage.liveView = circleView
let circleLayer = CAShapeLayer()
let width = circleView.frame.size.width;
let height = circleView.frame.size.height;
circleLayer.bounds = CGRectMake(-lineWidth/2, -lineWidth/2, width, height)
circleLayer.position = CGPointMake(width/2, height/2)
var c = circleView.frame
c.size.width -= lineWidth
c.size.height -= lineWidth
let path = UIBezierPath(roundedRect: c, cornerRadius: viewWidth/2)
circleLayer.path = path.CGPath
circleLayer.strokeEnd = end
circleLayer.lineCap = kCALineCapRound
circleLayer.fillColor = UIColor.clearColor().CGColor
circleLayer.strokeColor = UIColor.blueColor().CGColor
circleLayer.lineWidth = lineWidth
circleView.layer.addSublayer(circleLayer)
class Responder : NSObject {
func tick() {
end += 0.1
circleLayer.strokeEnd = end
}
}
let responder = Responder()
NSTimer.scheduledTimerWithTimeInterval(1.0, target: responder, selector: #selector(Responder.tick), userInfo: nil, repeats: true)
@funkyboy
Copy link
Copy Markdown
Author

funkyboy commented May 2, 2016

Preview
aaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment