93 lines
2.8 KiB
Swift
93 lines
2.8 KiB
Swift
//
|
|
// NotificationsNavBarIPAD.swift
|
|
// OpenVPN
|
|
//
|
|
// Created by Lizaveta Malinouskaya on 24.08.21.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol NotificationNavBarOutput {
|
|
func didTapCloseButton()
|
|
func viewIsReady()
|
|
}
|
|
|
|
class NotificationsNavBarIPAD: UIView {
|
|
|
|
// MARK: - Constant
|
|
enum Constant {
|
|
enum Geometry {
|
|
static let nbHeight: CGFloat = 42
|
|
static let buttonTrailing: CGFloat = 19
|
|
}
|
|
enum Color {
|
|
static let bg = Colors.Notification.nbBg.color
|
|
static let accent = Colors.Notification.accent.color
|
|
}
|
|
enum String {
|
|
static let title = NSLocalizedString("notificationCenter.navBar.title", comment: "Notification Center")
|
|
}
|
|
enum Image {
|
|
static let close = UIImage(named: "notification.close")
|
|
}
|
|
enum Font {
|
|
static let title = UIFont.primary(size: 12, weight: .medium)
|
|
}
|
|
}
|
|
// MARK: - Property
|
|
var output: NotificationNavBarOutput
|
|
|
|
// MARK: - init
|
|
|
|
public init(with output: NotificationNavBarOutput) {
|
|
self.output = output
|
|
super.init(frame: .zero)
|
|
self.setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: - UI
|
|
|
|
private func setupUI() {
|
|
self.translatesAutoresizingMaskIntoConstraints = false
|
|
self.backgroundColor = Constant.Color.bg
|
|
self.setupTitle(with: self)
|
|
self.setupCloseButton(with: self)
|
|
}
|
|
|
|
private func setupTitle(with container: UIView) {
|
|
let title = UILabel()
|
|
title.text = Constant.String.title
|
|
title.textColor = Constant.Color.accent
|
|
title.font = Constant.Font.title
|
|
title.translatesAutoresizingMaskIntoConstraints = false
|
|
container.addSubview(title)
|
|
|
|
NSLayoutConstraint.activate([
|
|
title.centerYAnchor.constraint(equalTo: container.centerYAnchor, constant: 1),
|
|
title.centerXAnchor.constraint(equalTo: container.centerXAnchor)
|
|
])
|
|
}
|
|
|
|
private func setupCloseButton(with container: UIView) {
|
|
let closeButton = UIButton()
|
|
closeButton.translatesAutoresizingMaskIntoConstraints = false
|
|
closeButton.setImage(Constant.Image.close, for: .normal)
|
|
closeButton.addTarget(container, action: #selector(self.didTapClose), for: .touchUpInside)
|
|
container.addSubview(closeButton)
|
|
|
|
NSLayoutConstraint.activate([
|
|
closeButton.centerYAnchor.constraint(equalTo: container.centerYAnchor),
|
|
closeButton.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -Constant.Geometry.buttonTrailing)
|
|
])
|
|
}
|
|
|
|
@objc private func didTapClose() {
|
|
self.output.didTapCloseButton()
|
|
}
|
|
}
|