-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathCustomNavigationView.swift
72 lines (57 loc) · 1.8 KB
/
CustomNavigationView.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
62
63
64
65
66
67
68
69
70
71
72
//
// CustomNavigationView.swift
// Lockdown
//
// Created by Oleg Dreyman on 23.10.2020.
// Copyright © 2020 Confirmed Inc. All rights reserved.
//
import UIKit
final class CustomNavigationView: UIView {
var title: String = "" {
didSet {
titleView.text = title
}
}
var buttonTitle: String = NSLocalizedString("CLOSE", comment: "") {
didSet {
button.setTitle(buttonTitle, for: .normal)
}
}
private(set) var buttonCallback: () -> () = { }
@discardableResult
func onButtonPressed(_ callback: @escaping () -> ()) -> CustomNavigationView {
buttonCallback = callback
return self
}
let titleView = UILabel()
private let button = UIButton(type: .system)
init() {
super.init(frame: .zero)
didLoad()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func didLoad() {
addSubview(titleView)
titleView.textAlignment = .center
titleView.text = title
titleView.font = fontMedium17
titleView.anchors.centerX.align()
titleView.anchors.top.pin(inset: 18)
addSubview(button)
button.titleLabel?.font = fontBold13
button.contentHorizontalAlignment = .leading
button.tintColor = .confirmedBlue
button.setTitle(buttonTitle, for: .normal)
button.anchors.centerY.equal(titleView.anchors.centerY)
button.anchors.leading.marginsPin(inset: 8)
button.anchors.bottom.marginsPin()
button.addTarget(self, action: #selector(buttonDidPress), for: .touchUpInside)
}
@objc
func buttonDidPress() {
buttonCallback()
}
}