-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRing.swift
40 lines (30 loc) · 1.16 KB
/
Ring.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Ring.swift
// Morphi
//
// Created by phimage on 18/07/2019.
// Copyright © 2019 phimage. All rights reserved.
//
import SwiftUI
/// An ring centered on the frame of the view containing it.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct Ring: Shape {
/// The raidus of the ring.
public var radius: CGFloat
public init(radius: CGFloat) {
self.radius = radius
}
/// Describes this shape as a path within a rectangular frame of reference.
///
/// - Parameter rect: The frame of reference for describing this shape.
/// - Returns: A path that describes this shape.
public func path(in rect: CGRect) -> Path {
var path = Path()
let center = rect.center
let (innerRadius, outerRadius) = rect.radii(for: radius)
path.addArc(center: .zero, radius: innerRadius, startAngle: .zero, endAngle: .pi * 2, clockwise: false)
path.move(to: CGPoint(x: outerRadius, y: 0))
path.addArc(center: .zero, radius: outerRadius, startAngle: .zero, endAngle: .pi * 2, clockwise: false)
return path.applying(CGAffineTransform(translationX: center.x, y: center.y))
}
}