Skip to content

Instantly share code, notes, and snippets.

@bdalziel
Last active August 18, 2016 19:35
Show Gist options
  • Save bdalziel/7b2ca6afd058c30cc3a3 to your computer and use it in GitHub Desktop.
Save bdalziel/7b2ca6afd058c30cc3a3 to your computer and use it in GitHub Desktop.
Relies on SwiftHEXColors for some nice UIColor extensions https://github.com/thii/SwiftHEXColors
//
// AppearanceManager.swift
//
// Created by Ben Dalziel on 2/17/16.
//
import UIKit
class AppearanceManager {
class func styleUINavigationBar() {
MyUINavigationBar.appearance().backgroundColor = ColorUtil.uiColor(AppUIColors.NavBarBackground)
MyUINavigationBar.appearance().tintColor = ColorUtil.uiColor(AppUIColors.NavBarTint)
}
}
//
// ColorUtil.swift
//
// Created by Ben Dalziel on 2/17/16.
//
import SwiftHEXColors
public indirect enum AppUIColors: Int {
case NavBarBackground,
NavBarTint,
NavBarShadow
}
class ColorUtil {
enum AppColors: String {
case Beige = "#f5efe0",
Gold = "#cda582",
// Alternate colors - use sparingly
GoldAlt = "#e1b996"
}
class func uiColor(appUIColor: AppUIColors) -> UIColor {
switch appUIColor {
case .NavBarBackground:
return color(AppColors.Beige)
case .NavBarTint :
return color(AppColors.Gold)
case .NavBarShadow :
return colorWithAlpha(AppColors.GoldAlt, alpha: 0.7)
}
}
// Conveniences unwrap raw value hex color value from enum
class func color(appColor: AppColors) -> UIColor {
return UIColor(hexString: appColor.rawValue)!
}
class func colorWithAlpha(appColor: AppColors, alpha: Float) -> UIColor {
return UIColor(hexString: appColor.rawValue, alpha: alpha)!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment