-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExs.swift
47 lines (30 loc) · 1.29 KB
/
Exs.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
45
46
47
import UIKit
extension UIColor {
func colorHex(_ rgb:String) -> UIColor {
var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
if rgb.hasPrefix("#") {
let hex:String = rgb.replacingOccurrences(of: "#", with: "")
let scanner = Scanner(string: hex)
var hexval:CUnsignedLongLong = 0
if scanner.scanHexInt64(&hexval) {
red = CGFloat((hexval & 0xFF0000) >> 16) / 255.0
green = CGFloat((hexval & 0x00FF00) >> 8) / 255.0
blue = CGFloat(hexval & 0x0000FF) / 255.0
}else {
fatalError("@Scan error")
}
}else {
fatalError("@Need # in parameter!")
}
let color = UIColor(red: red, green: green, blue: blue, alpha: 1)
return color
}
func rgb(_ red: CGFloat,_ green: CGFloat,_ blue: CGFloat) -> AnyObject {
return UIColor(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: 1.0).cgColor as AnyObject
}
func hexx(_ str:String) -> AnyObject {
return UIColor().colorHex(str).cgColor as AnyObject
}
}