-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuHeaderView.swift
More file actions
125 lines (100 loc) · 3.68 KB
/
MenuHeaderView.swift
File metadata and controls
125 lines (100 loc) · 3.68 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
117
118
119
120
121
122
123
124
125
//
// MenuHeaderView.swift
// Eatery Blue
//
// Created by William Ma on 12/23/21.
//
import UIKit
class MenuHeaderView: UIView {
// MARK: - Properties (View)
let titleLabel = UILabel()
let subtitleLabel = UILabel()
let buttonView = UIView()
let menuInaccuracyLabel = UILabel()
// MARK: - Properties (Data)
var notice: String? {
didSet {
setUpMenuInaccuracyLabel()
}
}
// MARK: - Init
override init(frame: CGRect) {
super.init(frame: frame)
setUpSelf()
setUpConstraints()
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setUpSelf() {
addSubview(titleLabel)
setUpTitleLabel()
addSubview(subtitleLabel)
setUpSubtitleLabel()
addSubview(buttonView)
setUpButtonImageView()
addSubview(menuInaccuracyLabel)
setUpMenuInaccuracyLabel()
}
private func setUpTitleLabel() {
titleLabel.font = .preferredFont(for: .largeTitle, weight: .bold)
titleLabel.textColor = UIColor.Eatery.primaryText
}
private func setUpSubtitleLabel() {
subtitleLabel.font = .preferredFont(for: .subheadline, weight: .semibold)
subtitleLabel.textColor = UIColor.Eatery.secondaryText
}
private func setUpButtonImageView() {
buttonView.backgroundColor = UIColor.Eatery.gray00
buttonView.layer.cornerRadius = 21
buttonView.layoutMargins = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 14)
let imageView = UIImageView()
imageView.image = UIImage(named: "EateryCalendar")
imageView.contentMode = .center
buttonView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.width.height.equalTo(36)
make.leading.equalTo(buttonView.layoutMarginsGuide)
make.centerY.equalTo(buttonView)
}
let titleLabel = UILabel()
titleLabel.text = "Change Date"
titleLabel.font = .preferredFont(for: .subheadline, weight: .semibold)
titleLabel.textColor = UIColor.Eatery.primaryText
buttonView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.leading.equalTo(imageView.snp.trailing)
make.trailing.lessThanOrEqualTo(buttonView.layoutMarginsGuide)
make.centerY.equalTo(buttonView)
}
buttonView.isUserInteractionEnabled = true
}
private func setUpMenuInaccuracyLabel() {
menuInaccuracyLabel.text = notice
menuInaccuracyLabel.font = .preferredFont(for: .caption2, weight: .semibold)
menuInaccuracyLabel.textColor = UIColor.Eatery.secondaryText
menuInaccuracyLabel.lineBreakMode = .byWordWrapping
menuInaccuracyLabel.numberOfLines = 0
}
private func setUpConstraints() {
titleLabel.snp.makeConstraints { make in
make.top.leading.equalTo(layoutMarginsGuide)
make.trailing.lessThanOrEqualTo(buttonView.snp.leading)
}
subtitleLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(4)
make.leading.equalTo(layoutMarginsGuide)
}
buttonView.snp.makeConstraints { make in
make.trailing.equalTo(layoutMarginsGuide)
make.top.equalTo(layoutMarginsGuide).offset(8)
make.height.equalTo(42)
make.width.equalTo(156)
}
menuInaccuracyLabel.snp.makeConstraints { make in
make.top.equalTo(subtitleLabel.snp.bottom).offset(12)
make.leading.trailing.bottom.equalTo(layoutMarginsGuide)
}
}
}