Skip to content

Instantly share code, notes, and snippets.

@DimaVartanian
Last active May 10, 2017 21:47
Show Gist options
  • Save DimaVartanian/eaf3c7087f69f29c56f7bb54f5326abb to your computer and use it in GitHub Desktop.
Save DimaVartanian/eaf3c7087f69f29c56f7bb54f5326abb to your computer and use it in GitHub Desktop.
Nested Gauge
//
// NestedGauge.swift
// circle
//
// Created by Dima Vartanian on 5/10/17.
// Copyright © 2017 Dima Vartanian. All rights reserved.
//
import UIKit
class NestedGauge: UIView {
override func draw(_ rect: CGRect) {
super.draw(rect)
let path = UIBezierPath()
let path2 = UIBezierPath()
let outerRadius: CGFloat = (self.bounds.size.width / 2)
let innerRadius: CGFloat = outerRadius - 20
let outerRadius2: CGFloat = innerRadius - 5
let innerRadius2: CGFloat = outerRadius2 - 20
let sliceCount = 30
let fullCircle = CGFloat(2 * M_PI)
for i in 0..<sliceCount {
let angle = CGFloat(i) * fullCircle / CGFloat(sliceCount)
UIColor.red.setStroke()
let inner = CGPoint(x: innerRadius * cos(angle), y: innerRadius * sin(angle))
let outer = CGPoint(x: outerRadius * cos(angle), y: outerRadius * sin(angle))
path.move(to: CGPoint(x: inner.x + outerRadius, y: inner.y + outerRadius))
path.addLine(to: CGPoint(x: outer.x + outerRadius, y: outer.y + outerRadius))
path.stroke()
UIColor.blue.setStroke()
let inner2 = CGPoint(x: innerRadius2 * cos(angle), y: innerRadius2 * sin(angle))
let outer2 = CGPoint(x: outerRadius2 * cos(angle), y: outerRadius2 * sin(angle))
path2.move(to: CGPoint(x: inner2.x + outerRadius, y: inner2.y + outerRadius))
path2.addLine(to: CGPoint(x: outer2.x + outerRadius, y: outer2.y + outerRadius))
path2.stroke()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment