|
7 | 7 |
|
8 | 8 | import UIKit |
9 | 9 |
|
| 10 | +protocol ConfirmationViewDelegate:AnyObject{ |
| 11 | + func tappedConfirmationButton() |
| 12 | +} |
| 13 | + |
10 | 14 | class ConfirmationView: UIView { |
| 15 | + |
| 16 | + weak var delegate: ConfirmationViewDelegate? |
| 17 | + |
| 18 | + private lazy var confirmationImage: UIImageView = { |
| 19 | + let element = UIImageView() |
| 20 | + element.translatesAutoresizingMaskIntoConstraints = false |
| 21 | + element.image = UIImage(named: "checkmark.circle.fill") |
| 22 | + element.contentMode = .scaleAspectFill |
| 23 | + element.tintColor = UIColor(red: 0/255, green: 220/255, blue: 41/255, alpha: 1) |
| 24 | + return element |
| 25 | + }() |
| 26 | + |
| 27 | + private lazy var confirmationLabel: UILabel = { |
| 28 | + let element = UILabel() |
| 29 | + element.translatesAutoresizingMaskIntoConstraints = false |
| 30 | + element.text = "Your transfer was successful" |
| 31 | + element.font = UIFont.systemFont(ofSize: 18, weight: .bold) |
| 32 | + return element |
| 33 | + }() |
| 34 | + |
| 35 | + private lazy var confirmationButton: UIButton = { |
| 36 | + let element = UIButton() |
| 37 | + element.translatesAutoresizingMaskIntoConstraints = false |
| 38 | + element.backgroundColor = UIColor(red: 0/255, green: 120/255, blue: 255/255, alpha: 1) |
| 39 | + element.layer.cornerRadius = 10 |
| 40 | + element.setTitle("Nice", for: .normal) |
| 41 | + element.setTitleColor(UIColor.white, for: .normal) |
| 42 | + element.addTarget(self, action: #selector(self.confirmationButtonPressed), for: .touchUpInside) |
| 43 | + return element |
| 44 | + }() |
| 45 | + |
| 46 | + @objc func confirmationButtonPressed(){ |
| 47 | + print("Configurar ConfirmationViewDelegate") |
| 48 | + } |
| 49 | + |
| 50 | + override init(frame: CGRect) { |
| 51 | + super.init(frame: frame) |
| 52 | + setUpViews() |
| 53 | + buildHierarchy() |
| 54 | + setupConstraints() |
| 55 | + } |
| 56 | + |
| 57 | + required init?(coder: NSCoder) { |
| 58 | + fatalError("init(coder:) has not been implemented") |
| 59 | + } |
| 60 | +} |
11 | 61 |
|
| 62 | +extension ConfirmationView: ViewCodable{ |
| 63 | + |
| 64 | + func setUpViews(){ |
| 65 | + backgroundColor = .white |
| 66 | + } |
| 67 | + |
| 68 | + func buildHierarchy(){ |
| 69 | + addSubview(confirmationImage) |
| 70 | + addSubview(confirmationLabel) |
| 71 | + addSubview(confirmationButton) |
| 72 | + } |
| 73 | + |
| 74 | + func setupConstraints() { |
| 75 | + NSLayoutConstraint.activate([ |
| 76 | + confirmationImage.centerXAnchor.constraint(equalTo: self.centerXAnchor), |
| 77 | + confirmationImage.centerYAnchor.constraint(equalTo: self.centerYAnchor), |
| 78 | + confirmationImage.widthAnchor.constraint(equalToConstant: 64), |
| 79 | + confirmationImage.heightAnchor.constraint(equalToConstant: 64), |
| 80 | + |
| 81 | + confirmationLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor), |
| 82 | + confirmationLabel.topAnchor.constraint(equalTo: self.confirmationImage.bottomAnchor, constant: 8), |
| 83 | + |
| 84 | + confirmationButton.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor, constant: -32), |
| 85 | + confirmationButton.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor, constant: 32), |
| 86 | + confirmationButton.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor, constant: -32), |
| 87 | + confirmationButton.heightAnchor.constraint(equalToConstant: 64) |
| 88 | + ]) |
| 89 | + } |
12 | 90 | } |
0 commit comments