80 lines
2.6 KiB
Swift
80 lines
2.6 KiB
Swift
//
|
|
// PrivilegeDeniedOverlay.swift
|
|
// QuickLocation
|
|
//
|
|
|
|
import UIKit
|
|
|
|
final class PrivilegeDeniedOverlay: UIView {
|
|
|
|
var onAction: (() -> Void)?
|
|
|
|
private let imageView = UIImageView()
|
|
private let titleLab = UILabel()
|
|
private let messageLab = UILabel()
|
|
private let actionBtn = UIButton(type: .custom)
|
|
private let contentStack = UIStackView()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
isHidden = true
|
|
clipsToBounds = true
|
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
imageView.clipsToBounds = true
|
|
imageView.isUserInteractionEnabled = false
|
|
addSubview(imageView)
|
|
imageView.layoutChain.edges()
|
|
|
|
titleLab.font = .systemFont(ofSize: 16, weight: .semibold)
|
|
titleLab.textColor = UIColor(hexStr: "#293445")
|
|
titleLab.textAlignment = .center
|
|
|
|
messageLab.font = .systemFont(ofSize: 16, weight: .semibold)
|
|
messageLab.textColor = UIColor(hexStr: "#293445")
|
|
messageLab.textAlignment = .center
|
|
|
|
actionBtn.titleLabel?.font = .systemFont(ofSize: 16, weight: .semibold)
|
|
actionBtn.setTitleColor(.white, for: .normal)
|
|
actionBtn.backgroundColor = UIColor(hexStr: "#16B3FF")
|
|
actionBtn.cornerRadius = 10
|
|
actionBtn.addTarget(self, action: #selector(tapAction), for: .touchUpInside)
|
|
actionBtn.layoutChain.width(160).height(44)
|
|
|
|
contentStack.axis = .vertical
|
|
contentStack.alignment = .center
|
|
contentStack.spacing = 6
|
|
contentStack.addArrangedSubview(titleLab)
|
|
contentStack.addArrangedSubview(messageLab)
|
|
contentStack.setCustomSpacing(16, after: messageLab)
|
|
contentStack.addArrangedSubview(actionBtn)
|
|
addSubview(contentStack)
|
|
contentStack.layoutChain.centerX().centerY()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
func configure(title: String, message: String, actionTitle: String, imageName: String) {
|
|
imageView.image = UIImage(named: imageName)
|
|
titleLab.text = title
|
|
messageLab.text = message
|
|
actionBtn.setTitle(actionTitle, for: .normal)
|
|
let showsContent = !title.isEmpty || !message.isEmpty || !actionTitle.isEmpty
|
|
contentStack.isHidden = !showsContent
|
|
actionBtn.isHidden = actionTitle.isEmpty
|
|
titleLab.isHidden = title.isEmpty
|
|
messageLab.isHidden = message.isEmpty
|
|
}
|
|
|
|
func setVisible(_ visible: Bool) {
|
|
isHidden = !visible
|
|
isUserInteractionEnabled = visible
|
|
}
|
|
|
|
@objc private func tapAction() {
|
|
onAction?()
|
|
}
|
|
}
|