75 lines
1.9 KiB
Swift
75 lines
1.9 KiB
Swift
import UIKit
|
|
|
|
class BaseNavigationView: UIView {
|
|
|
|
let titleLabel: UILabel
|
|
let backBtn: UIButton
|
|
var onBackTapped: (() -> Void)?
|
|
|
|
private let rightStack: UIStackView = {
|
|
let stack = UIStackView()
|
|
stack.axis = .horizontal
|
|
stack.alignment = .fill
|
|
stack.distribution = .fill
|
|
stack.spacing = 12
|
|
return stack
|
|
}()
|
|
|
|
init(title: String) {
|
|
backBtn = UIButton(type: .custom)
|
|
backBtn.setImage(UIImage(named: "Common/back"), for: .normal)
|
|
backBtn.extendEdgeInsets = UIEdgeInsets(top: 54, left: 15, bottom: 100, right: 100)
|
|
|
|
titleLabel = UILabel()
|
|
titleLabel.font = .systemFont(ofSize: 18, weight: .medium)
|
|
titleLabel.textColor = ThemeManager.shared.color.titleAuxColor
|
|
titleLabel.textAlignment = .center
|
|
titleLabel.text = title
|
|
|
|
super.init(frame: .zero)
|
|
|
|
backgroundColor = .clear
|
|
addSubview(backBtn)
|
|
addSubview(titleLabel)
|
|
addSubview(rightStack)
|
|
|
|
backBtn.layoutChain
|
|
.centerY(titleLabel)
|
|
.left(15)
|
|
.width(24)
|
|
.height(24)
|
|
|
|
titleLabel.layoutChain
|
|
.top(kStatusBarHeight + 12)
|
|
.centerY(backBtn)
|
|
.centerX()
|
|
|
|
rightStack.layoutChain
|
|
.centerY(titleLabel)
|
|
.right(15)
|
|
.height(24)
|
|
|
|
backBtn.addTarget(self, action: #selector(handleBackTap), for: .touchUpInside)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc private func handleBackTap() {
|
|
if let onBackTapped = onBackTapped {
|
|
onBackTapped()
|
|
} else {
|
|
AppRouter.shared.popOrDismiss()
|
|
}
|
|
}
|
|
|
|
func addRightButton(_ button: UIButton) {
|
|
rightStack.addArrangedSubview(button)
|
|
}
|
|
|
|
func addRightView(_ view: UIView) {
|
|
rightStack.addArrangedSubview(view)
|
|
}
|
|
}
|