|
| 1 | +// |
| 2 | +// UserProfileHeaderView.swift |
| 3 | +// FinanceApp |
| 4 | +// |
| 5 | +// Created by Cleber Reis on 18/10/22. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | + |
| 10 | +final class UserProfileHeaderView: UIStackView { |
| 11 | + |
| 12 | + private lazy var profileImage: UIImageView = { |
| 13 | + let image = UIImageView() |
| 14 | + image.translatesAutoresizingMaskIntoConstraints = false |
| 15 | + image.image = UIImage(named: "avatar-placeholder") |
| 16 | + image.contentMode = .scaleAspectFill |
| 17 | + image.layer.cornerRadius = 40 |
| 18 | + image.layer.masksToBounds = true |
| 19 | + |
| 20 | + return image |
| 21 | + }() |
| 22 | + |
| 23 | + private lazy var titleLabel: UILabel = { |
| 24 | + let label = UILabel() |
| 25 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 26 | + label.font = .systemFont(ofSize: 18, weight: .bold) |
| 27 | + label.text = "Irma Flores" |
| 28 | + label.textColor = .black |
| 29 | + |
| 30 | + return label |
| 31 | + }() |
| 32 | + |
| 33 | + private lazy var agencyLabel: UILabel = { |
| 34 | + let label = UILabel() |
| 35 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 36 | + label.text = "Agency 001" |
| 37 | + label.font = .systemFont(ofSize: 14, weight: .regular) |
| 38 | + label.textColor = .lightGray |
| 39 | + |
| 40 | + return label |
| 41 | + }() |
| 42 | + |
| 43 | + private lazy var accountLabel: UILabel = { |
| 44 | + let label = UILabel() |
| 45 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 46 | + label.text = "Account 123456-7" |
| 47 | + label.font = .systemFont(ofSize: 14, weight: .regular) |
| 48 | + label.textColor = .lightGray |
| 49 | + |
| 50 | + return label |
| 51 | + }() |
| 52 | + |
| 53 | + private lazy var bankLabel: UILabel = { |
| 54 | + let label = UILabel() |
| 55 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 56 | + label.text = "DEVPASS Bank" |
| 57 | + label.font = .systemFont(ofSize: 14, weight: .regular) |
| 58 | + label.textColor = .lightGray |
| 59 | + |
| 60 | + return label |
| 61 | + }() |
| 62 | + |
| 63 | + override init(frame: CGRect) { |
| 64 | + super.init(frame: frame) |
| 65 | + backgroundColor = .systemGray5 |
| 66 | + setupView() |
| 67 | + } |
| 68 | + |
| 69 | + @available(*, unavailable) |
| 70 | + required init(coder: NSCoder) { |
| 71 | + fatalError("init(coder:) has not been implemented") |
| 72 | + } |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +extension UserProfileHeaderView: ViewCodable { |
| 77 | + |
| 78 | + func buildHierarchy() { |
| 79 | + addArrangedSubview(profileImage) |
| 80 | + addArrangedSubview(titleLabel) |
| 81 | + addArrangedSubview(agencyLabel) |
| 82 | + addArrangedSubview(accountLabel) |
| 83 | + addArrangedSubview(bankLabel) |
| 84 | + } |
| 85 | + |
| 86 | + func setupConstraints() { |
| 87 | + NSLayoutConstraint.activate([ |
| 88 | + profileImage.heightAnchor.constraint(equalToConstant: 80), |
| 89 | + profileImage.widthAnchor.constraint(equalToConstant: 80), |
| 90 | + ]) |
| 91 | + } |
| 92 | + |
| 93 | + func applyAdditionalChanges() { |
| 94 | + translatesAutoresizingMaskIntoConstraints = false |
| 95 | + axis = .vertical |
| 96 | + spacing = 8 |
| 97 | + alignment = .center |
| 98 | + } |
| 99 | +} |
0 commit comments