-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSiteInfoHeaderView.swift
More file actions
116 lines (97 loc) · 3 KB
/
Copy pathSiteInfoHeaderView.swift
File metadata and controls
116 lines (97 loc) · 3 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import UIKit
import WordPressShared
// MARK: - SiteInfoHeaderView
//
class SiteInfoHeaderView: UIView {
// MARK: - Outlets
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var subtitleLabel: UILabel!
@IBOutlet private var blavatarImageView: UIImageView!
// MARK: - Properties
/// Site Title
///
var title: String? {
get {
return titleLabel.text
}
set {
titleLabel.text = newValue
}
}
/// Site Subtitle
///
var subtitle: String? {
get {
return subtitleLabel.text
}
set {
subtitleLabel.text = newValue
}
}
/// When enabled, the Subtitle won't be rendered.
///
var subtitleIsHidden: Bool = true {
didSet {
refreshLabelStyles()
}
}
/// When enabled, renders a border around the Blavatar.
///
var blavatarBorderIsHidden: Bool = false {
didSet {
refreshBlavatarStyle()
}
}
/// Returns (or sets) the Site's Blavatar Image.
///
var blavatarImage: UIImage? {
get {
return blavatarImageView.image
}
set {
blavatarImageView.image = newValue
}
}
/// Downloads the Blavatar Image at the specified URL.
///
func downloadBlavatar(at path: String) {
blavatarImageView.image = .siteIconPlaceholderImage
if let url = URL(string: path) {
blavatarImageView.downloadImage(from: url)
}
}
// MARK: - Overridden Methods
override func awakeFromNib() {
super.awakeFromNib()
refreshLabelStyles()
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory else {
return
}
refreshLabelStyles()
}
}
// MARK: - Private
//
private extension SiteInfoHeaderView {
func refreshLabelStyles() {
let titleWeight: UIFont.Weight = subtitleIsHidden ? .regular : .semibold
titleLabel.font = WPStyleGuide.fontForTextStyle(.subheadline, fontWeight: titleWeight)
titleLabel.textColor = WPStyleGuide.darkGrey()
subtitleLabel.isHidden = subtitleIsHidden
subtitleLabel.font = WPStyleGuide.fontForTextStyle(.footnote)
subtitleLabel.textColor = WPStyleGuide.darkGrey()
}
func refreshBlavatarStyle() {
if blavatarBorderIsHidden {
blavatarImageView.layer.borderWidth = 0
blavatarImageView.tintColor = WordPressAuthenticator.shared.style.placeholderColor
} else {
blavatarImageView.layer.borderColor = WordPressAuthenticator.shared.style.instructionColor.cgColor
blavatarImageView.layer.borderWidth = 1
blavatarImageView.tintColor = WordPressAuthenticator.shared.style.placeholderColor
}
}
}