Skip to content

Instantly share code, notes, and snippets.

@ashtonmeuser
Created November 8, 2017 21:05
Show Gist options
  • Select an option

  • Save ashtonmeuser/e050b859d237d7440531f01338e6fd3b to your computer and use it in GitHub Desktop.

Select an option

Save ashtonmeuser/e050b859d237d7440531f01338e6fd3b to your computer and use it in GitHub Desktop.
Circular UIView, efficient when resizing
//
// CircleView.swift
//
// Created by Ashton Meuser on 2017-11-08.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import UIKit
class CircleView: UIView {
var fillColor: UIColor = UIColor.clear
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
isOpaque = false
backgroundColor = UIColor.clear
}
override func layoutSubviews() {
super.layoutSubviews()
setNeedsDisplay()
}
override func draw(_ rect: CGRect) {
let path = UIBezierPath(ovalIn: rect)
fillColor.setFill()
path.fill()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment