Skip to content

Instantly share code, notes, and snippets.

@janodev
Created April 20, 2017 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janodev/274ebc60d42898d5505e267470f50ba4 to your computer and use it in GitHub Desktop.
Save janodev/274ebc60d42898d5505e267470f50ba4 to your computer and use it in GitHub Desktop.
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)
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)
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