-
-
Save tigerraj32/6730c2af6c4b21d195b74b974938daf0 to your computer and use it in GitHub Desktop.
Color Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ColorLibrary.swift | |
// | |
// Created on 06/01/2017. | |
// | |
// Generated by PaintCode Plugin for Sketch | |
// http://www.paintcodeapp.com/sketch | |
// | |
import UIKit | |
class ColorLibrary: NSObject { | |
//MARK: - Colors | |
static let themeColor = UIColor(hue: 0.246, saturation: 0.843, brightness: 0.826, alpha: 1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension UIColor { | |
func withAlpha(_ newAlpha: CGFloat) -> UIColor { | |
var hue: CGFloat = 1 | |
var saturation: CGFloat = 1 | |
var brightness: CGFloat = 1 | |
self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: nil) | |
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: newAlpha) | |
} | |
func highlight(withLevel highlight: CGFloat) -> UIColor { | |
var red: CGFloat = 1, green: CGFloat = 1 | |
var blue: CGFloat = 1, alpha: CGFloat = 1 | |
self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) | |
return UIColor(red: red * (1-highlight) + highlight, | |
green: green * (1-highlight) + highlight, | |
blue: blue * (1-highlight) + highlight, | |
alpha: alpha * (1-highlight) + highlight) | |
} | |
func shadow(withLevel shadow: CGFloat) -> UIColor { | |
var red: CGFloat = 1, green: CGFloat = 1 | |
var blue: CGFloat = 1, alpha: CGFloat = 1 | |
self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) | |
return UIColor(red: red * (1-shadow), | |
green: green * (1-shadow), | |
blue: blue * (1-shadow), | |
alpha: alpha * (1-shadow) + shadow) | |
} | |
static func hexColor(withString hexString: String, alpha: CGFloat) -> UIColor { | |
let hexString: String = (hexString as NSString).trimmingCharacters(in: .whitespacesAndNewlines) | |
let scanner = Scanner(string: hexString as String) | |
if hexString.hasPrefix("#") { | |
scanner.scanLocation = 1 | |
} | |
var color: UInt32 = 0 | |
scanner.scanHexInt32(&color) | |
let mask = 0x000000FF | |
let r = Int(color >> 16) & mask | |
let g = Int(color >> 8) & mask | |
let b = Int(color) & mask | |
let red = CGFloat(r) / 255.0 | |
let green = CGFloat(g) / 255.0 | |
let blue = CGFloat(b) / 255.0 | |
return UIColor(red: red, green: green, blue: blue, alpha: alpha) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment