-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeUtils.swift
44 lines (35 loc) · 1.58 KB
/
ThemeUtils.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// ThemeUtils.swift
// Gank
//
// Created by 魏星 on 16/7/16.
// Copyright © 2016年 wx. All rights reserved.
//
import Foundation
import UIKit
public class ThemeUtil {
public static let DARK_PRIMARY_COLOR = "#66CCFF"
public static let PRIMARY_COLOR = "#E91E63"
public static let ACCENT_COLOR = "#FF4081"
public static let DIVIDER_COLOR = "#B6B6B6"
public static let LIGHT_PRIMARY_COLOR = "#F8BBD0"
public static let SECONDARY_TEXT_COLOR = "#727272"
public static let PRIMARY_TEXT_COLOR = "#212121"
static func colorWithHexString (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = (cString as NSString).substringFromIndex(1)
}
if (cString.characters.count != 6) {
return UIColor.grayColor()
}
let rString = (cString as NSString).substringToIndex(2)
let gString = ((cString as NSString).substringFromIndex(2) as NSString).substringToIndex(2)
let bString = ((cString as NSString).substringFromIndex(4) as NSString).substringToIndex(2)
var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0;
NSScanner(string: rString).scanHexInt(&r)
NSScanner(string: gString).scanHexInt(&g)
NSScanner(string: bString).scanHexInt(&b)
return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: CGFloat(1))
}
}