Skip to content

Commit 570806f

Browse files
committed
Purely return views
1 parent 7564207 commit 570806f

File tree

1 file changed

+5
-71
lines changed

1 file changed

+5
-71
lines changed

Sources/HeaderView.swift

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,22 @@
11
import UIKit
22

3-
protocol HeaderViewDelegate: class {
4-
func headerViewDidPressClose(_ headerView: HeaderView)
5-
}
6-
7-
/**
8-
Header view that simulates a navigation bar.
9-
*/
10-
final class HeaderView: UIView {
11-
/// Title label.
12-
private lazy var label: UILabel = {
3+
/// UI elements on the navigation bar
4+
final class HeaderElement {
5+
static func makeLabel() -> UILabel {
136
let label = UILabel()
147
label.text = Title.text
158
label.font = Title.font
169
label.textColor = Title.color
17-
label.backgroundColor = Title.backgroundColor
1810
label.numberOfLines = 1
1911
label.textAlignment = .center
2012
return label
21-
}()
13+
}
2214

23-
/// Close button.
24-
private lazy var button: UIButton = {
15+
static func makeCloseButton() -> UIButton {
2516
let button = UIButton(type: .system)
2617
button.setTitle(CloseButton.text, for: UIControlState())
2718
button.titleLabel?.font = CloseButton.font
2819
button.tintColor = CloseButton.color
29-
button.addTarget(self, action: #selector(buttonDidPress), for: .touchUpInside)
3020
return button
31-
}()
32-
33-
/// Header view delegate.
34-
weak var delegate: HeaderViewDelegate?
35-
36-
// MARK: - Initialization
37-
38-
/**
39-
Creates a new instance of `HeaderView`.
40-
41-
- Parameter frame: View frame.
42-
*/
43-
override init(frame: CGRect) {
44-
super.init(frame: frame)
45-
46-
backgroundColor = Title.backgroundColor
47-
48-
[label, button].forEach {
49-
addSubview($0)
50-
}
51-
}
52-
53-
required init?(coder aDecoder: NSCoder) {
54-
fatalError("init(coder:) has not been implemented")
55-
}
56-
57-
// MARK: - Layout
58-
59-
override func layoutSubviews() {
60-
super.layoutSubviews()
61-
62-
let insets = viewInsets
63-
let leadingPadding: CGFloat = 15 + insets.left
64-
let topPadding: CGFloat = 8 + insets.top
65-
let labelHeight: CGFloat = 40
66-
67-
button.sizeToFit()
68-
69-
button.frame.origin = CGPoint(
70-
x: leadingPadding,
71-
y: ((frame.height - button.frame.height) / 2) + topPadding
72-
)
73-
74-
label.frame = CGRect(
75-
x: 0, y: ((frame.height - labelHeight) / 2) + topPadding,
76-
width: frame.width, height: labelHeight
77-
)
78-
}
79-
80-
// MARK: - Actions
81-
82-
/**
83-
Close button action handler.
84-
*/
85-
@objc private func buttonDidPress() {
86-
delegate?.headerViewDidPressClose(self)
8721
}
8822
}

0 commit comments

Comments
 (0)