Skip to content

Instantly share code, notes, and snippets.

@emin-grbo
Last active November 14, 2021 19:08
Show Gist options
  • Save emin-grbo/81858fa2431add8be9ba21444bf3c6cc to your computer and use it in GitHub Desktop.
Save emin-grbo/81858fa2431add8be9ba21444bf3c6cc to your computer and use it in GitHub Desktop.
Water Colors
extension Color {
// MARK: Gradients
static var backgroundGradient = LinearGradient(colors: [Color(hex: "#50A7F7"), Color(hex: "#2566F6")], startPoint: .top, endPoint: .bottom)
static var topWaterColor = Color(hex: "#739BF7")
static var midWaterColor = Color(hex: "#5989F5")
static var backWaterColor = Color(hex: "#4979E7")
static var buttonGradient = LinearGradient(colors: [Color(hex: "#F4F8FA"), Color(hex: "#B6CCF7")], startPoint: .top, endPoint: .bottom)
}
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