Skip to content

Instantly share code, notes, and snippets.

@emin-grbo
Last active November 16, 2021 09:48
Show Gist options
  • Save emin-grbo/48912c8ebad2194c151811340007c636 to your computer and use it in GitHub Desktop.
Save emin-grbo/48912c8ebad2194c151811340007c636 to your computer and use it in GitHub Desktop.
Example of a ring designed in swiftUI for un:safe app (unsafe.undeadpixel.dev)
import SwiftUI
struct Ring: View {
var body: some View {
HStack {
Spacer()
ZStack(alignment: .trailing) {
Circle()
.strokeBorder(Color.circleGradientColor, lineWidth: 50)
Circle()
.foregroundColor(Color.circleAccentColor)
.frame(width: 50)
}
.padding(16)
.aspectRatio(1, contentMode: .fit)
Spacer()
}
.frame(width: 300, height: 300)
}
}
// These extensions would of coruse be moved to another file
extension Color {
static var circleAccentColor = Color(hex: "#E33F84")
static var circleGradientColor = AngularGradient(gradient: Gradient(colors: [Color(hex: "#E33F84"), Color(hex: "#B81258")]), center: .center)
}
extension Color {
init(hex: String) {
let r, g, b: CGFloat
if hex.hasPrefix("#") {
let start = hex.index(hex.startIndex, offsetBy: 1)
let hexColor = String(hex[start...])
if hexColor.count == 6 {
let scanner = Scanner(string: hexColor)
var hexNumber: UInt64 = 0
if scanner.scanHexInt64(&hexNumber) {
r = CGFloat((hexNumber & 0xff0000) >> 16) / 255
g = CGFloat((hexNumber & 0x00ff00) >> 8) / 255
b = CGFloat((hexNumber & 0x0000ff)) / 255
self.init(.displayP3, red: Double(r), green: Double(g), blue: Double(b), opacity: 1)
return
}
}
}
self.init(.displayP3, red: 1, green: 1, blue: 1, opacity: 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment