-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUINavigationBar+Mistica.swift
61 lines (53 loc) · 1.93 KB
/
UINavigationBar+Mistica.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
61
//
// UINavigationBar+Mistica.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//
import UIKit
public extension UINavigationBar {
class var misticaLargeTitleTextAttributes: [NSAttributedString.Key: Any] {
textAttributes(for: .textPreset7(constrainedToPreferredSize: .large), color: UIColor.textNavigationBarPrimary)
}
class var misticaTitleTextAttributes: [NSAttributedString.Key: Any] {
textAttributes(for: .textPreset4(weight: .navigationBar, constrainedToPreferredSize: .large), color: UIColor.textNavigationBarPrimary)
}
func applyMisticaStyle() {
applyCommonOpaqueStyle()
shadowImage = UIImage()
}
}
private extension UINavigationBar {
func applyCommonOpaqueStyle() {
tintColor = .textNavigationBarPrimary
barTintColor = .navigationBarBackground
isTranslucent = false
layoutMargins.left = 16
layoutMargins.right = 16
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.shadowColor = .clear
navBarAppearance.backgroundColor = .navigationBarBackground
navBarAppearance.largeTitleTextAttributes = UINavigationBar.misticaLargeTitleTextAttributes
navBarAppearance.titleTextAttributes = UINavigationBar.misticaTitleTextAttributes
standardAppearance = navBarAppearance
compactAppearance = navBarAppearance
scrollEdgeAppearance = navBarAppearance
}
class func textAttributes(for font: UIFont, color: UIColor) -> [NSAttributedString.Key: Any] {
[
.font: font,
.foregroundColor: color,
.shadow: NSShadow.clear()
]
}
}
private extension NSShadow {
class func clear() -> NSShadow {
let shadow = NSShadow()
shadow.shadowColor = UIColor.clear
shadow.shadowOffset = .zero
return shadow
}
}