-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathUIColor+DarkMode.swift
60 lines (53 loc) · 1.71 KB
/
UIColor+DarkMode.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
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// UIColor+DarkMode.swift
// OpenGpxTracker
//
// Created by Vincent on 29/11/19.
//
import UIKit
@available(iOS 13.0, *)
/// To better support dark mode color switches.
extension UIColor {
/// Main UI color
static let mainUIColor = UIColor { (traitCollection: UITraitCollection) -> UIColor in
switch traitCollection.userInterfaceStyle {
case .unspecified, .light:
return UIColor(red: 0, green: 0.61, blue: 0.86, alpha: 1)
case .dark:
return .white
default:
return UIColor(red: 0, green: 0.61, blue: 0.86, alpha: 1)
}
}
/// Returns a colour opposite of trait collection (i.e. light gets black, dark gets white.)
static let blackAndWhite = UIColor { (traitCollection: UITraitCollection) -> UIColor in
switch traitCollection.userInterfaceStyle {
case .unspecified, .light:
return .black
case .dark:
return .white
default:
return .systemGray
}
}
static let keyboardColor = UIColor { (traitCollection: UITraitCollection) -> UIColor in
switch traitCollection.userInterfaceStyle {
case .unspecified, .light:
return .lightKeyboard
case .dark:
return .darkKeyboard
default:
return .lightKeyboard
}
}
static let highlightKeyboardColor = UIColor { (traitCollection: UITraitCollection) -> UIColor in
switch traitCollection.userInterfaceStyle {
case .unspecified, .light:
return .highlightLightKeyboard
case .dark:
return .highlightDarkKeyboard
default:
return .highlightLightKeyboard
}
}
}