Created
April 20, 2017 06:25
-
-
Save janodev/274ebc60d42898d5505e267470f50ba4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
enum Colors: Int64 | |
{ | |
case black = 0x000000ff | |
case white = 0xffffffff | |
func color() -> UIColor | |
{ | |
let red = CGFloat((self.rawValue >> 24) & 0xff) / 255.0 | |
let green = CGFloat((self.rawValue >> 16) & 0xff) / 255.0 | |
let blue = CGFloat((self.rawValue >> 8) & 0xff) / 255.0 | |
let alpha = CGFloat((self.rawValue ) & 0xff) / 255.0 | |
return UIColor(red: red, green: green, blue: blue, alpha: alpha) | |
} | |
} | |
extension UIColor | |
{ | |
func highlight(withLevel highlight: CGFloat) -> UIColor { | |
// ... | |
} | |
} | |
let blue5 = Colors.white.color().highlight(withLevel: 0.95) |
This file contains hidden or 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
public struct Fonts | |
{ | |
enum SF: String | |
{ | |
case bold = "SanFranciscoRounded-Bold" | |
case regular = "SanFranciscoRounded-Regular" | |
func size(_ size: CGFloat) -> UIFont { | |
return UIFont(name: self.rawValue, size: size)! | |
} | |
} | |
} | |
let sf = Fonts.SF.regular.size(16.0) |
This file contains hidden or 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
protocol Style | |
{ | |
var headline: (UILabel)->() { get } | |
// ... any reusable element in your UI | |
} | |
struct OrangeStyle: Style | |
{ | |
let headline: (UILabel)->() = { label in | |
label.font = Fonts.SF.regular.size(16.0) | |
} | |
} | |
protocol Styleable {} | |
extension Styleable { | |
func apply(_ style: (Self)->())->Self { | |
style(self) | |
return self | |
} | |
} | |
extension UILabel: Styleable {} | |
let style: Style = OrangeStyle() | |
let title = UILabel().apply(style.headline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment