|
7 | 7 |
|
8 | 8 | import UIKit |
9 | 9 |
|
10 | | -class ActivityDetailsView: UIView { |
| 10 | +final class ActivityDetailsView: UIView { |
| 11 | + |
| 12 | + // MARK: Init |
| 13 | + init() { |
| 14 | + super.init(frame: .zero) |
| 15 | + self.backgroundColor = .white |
| 16 | + setupView() |
| 17 | + } |
| 18 | + |
| 19 | + required init?(coder: NSCoder) { |
| 20 | + return nil |
| 21 | + } |
| 22 | + |
| 23 | + // MARK: Interface Elements |
| 24 | + private lazy var vStack: UIStackView = { |
| 25 | + let stack = UIStackView() |
| 26 | + stack.translatesAutoresizingMaskIntoConstraints = false |
| 27 | + stack.alignment = .center |
| 28 | + stack.spacing = 10 |
| 29 | + stack.axis = .vertical |
| 30 | + |
| 31 | + return stack |
| 32 | + }() |
| 33 | + |
| 34 | + private lazy var vCenterStack: UIStackView = { |
| 35 | + let stack = UIStackView() |
| 36 | + stack.translatesAutoresizingMaskIntoConstraints = false |
| 37 | + stack.alignment = .center |
| 38 | + stack.spacing = 10 |
| 39 | + stack.axis = .vertical |
| 40 | + |
| 41 | + return stack |
| 42 | + }() |
| 43 | + |
| 44 | + private lazy var bagImage: UIImageView = { |
| 45 | + let image = UIImageView() |
| 46 | + image.translatesAutoresizingMaskIntoConstraints = false |
| 47 | + image.image = UIImage(named: "bag.circle.fill") |
| 48 | + image.contentMode = .scaleAspectFill |
| 49 | + image.tintColor = UIColor(red: 190/255, green: 81/255, blue: 255/255, alpha: 1) |
| 50 | + return image |
| 51 | + }() |
| 52 | + |
| 53 | + private lazy var mallLabel: UILabel = { |
| 54 | + let label = UILabel() |
| 55 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 56 | + label.text = "Mall" |
| 57 | + label.font = UIFont.boldSystemFont(ofSize: 20) |
| 58 | + label.textColor = .black |
| 59 | + return label |
| 60 | + }() |
| 61 | + |
| 62 | + private lazy var shoppingLabel: UILabel = { |
| 63 | + let label = UILabel() |
| 64 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 65 | + label.text = "Shopping" |
| 66 | + label.font = UIFont.systemFont(ofSize: 20) |
| 67 | + label.textColor = .gray |
| 68 | + return label |
| 69 | + }() |
| 70 | + |
| 71 | + private lazy var valueLabel: UILabel = { |
| 72 | + let label = UILabel() |
| 73 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 74 | + label.text = "$100.00" |
| 75 | + label.font = UIFont.boldSystemFont(ofSize: 50) |
| 76 | + label.textColor = .black |
| 77 | + return label |
| 78 | + }() |
| 79 | + |
| 80 | + private lazy var hourLabel: UILabel = { |
| 81 | + let label = UILabel() |
| 82 | + label.translatesAutoresizingMaskIntoConstraints = false |
| 83 | + label.text = "8:57 AM" |
| 84 | + label.font = UIFont.systemFont(ofSize: 20) |
| 85 | + label.textColor = .gray |
| 86 | + return label |
| 87 | + }() |
| 88 | + |
| 89 | + private lazy var reportIssueButton: UIButton = { |
| 90 | + let button = UIButton(type: .system) |
| 91 | + button.translatesAutoresizingMaskIntoConstraints = false |
| 92 | + button.setTitle("Report issue", for: .normal) |
| 93 | + button.titleLabel?.font = UIFont.systemFont(ofSize: 25) |
| 94 | + button.setTitleColor(UIColor.white , for: .normal) |
| 95 | + button.clipsToBounds = true |
| 96 | + button.layer.cornerRadius = 10 |
| 97 | + button.addTarget(self, action: #selector(self.tappedButton(sender:)), for: .touchUpInside) |
| 98 | + button.backgroundColor = UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1) |
| 99 | + return button |
| 100 | + }() |
| 101 | + |
| 102 | + //MARK: Functions |
| 103 | + @objc func tappedButton(sender: UIButton) { |
| 104 | + print("action disparada") |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +extension ActivityDetailsView: ViewCodable { |
11 | 109 |
|
| 110 | + func buildHierarchy() { |
| 111 | + addSubview(vStack) |
| 112 | + addSubview(vCenterStack) |
| 113 | + addSubview(reportIssueButton) |
| 114 | + vStack.addArrangedSubview(bagImage) |
| 115 | + vStack.addArrangedSubview(mallLabel) |
| 116 | + vStack.addArrangedSubview(shoppingLabel) |
| 117 | + vCenterStack.addArrangedSubview(valueLabel) |
| 118 | + vCenterStack.addArrangedSubview(hourLabel) |
| 119 | + } |
| 120 | + |
| 121 | + // MARK: Interface Constraints |
| 122 | + func setupConstraints() { |
| 123 | + |
| 124 | + let bagImageSize: CGFloat = 150 |
| 125 | + |
| 126 | + NSLayoutConstraint.activate([ |
| 127 | + vStack.topAnchor.constraint(equalTo: topAnchor, constant: 48), |
| 128 | + vStack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4), |
| 129 | + vStack.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -4), |
| 130 | + |
| 131 | + //Inside vStack |
| 132 | + bagImage.widthAnchor.constraint(equalToConstant: bagImageSize), |
| 133 | + bagImage.heightAnchor.constraint(equalToConstant: bagImageSize), |
| 134 | + ]) |
| 135 | + |
| 136 | + NSLayoutConstraint.activate([ |
| 137 | + vCenterStack.centerXAnchor.constraint(equalTo: centerXAnchor), |
| 138 | + vCenterStack.centerYAnchor.constraint(equalTo: centerYAnchor), |
| 139 | + ]) |
| 140 | + |
| 141 | + NSLayoutConstraint.activate([ |
| 142 | + reportIssueButton.heightAnchor.constraint(equalToConstant: 44), |
| 143 | + reportIssueButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16), |
| 144 | + reportIssueButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), |
| 145 | + reportIssueButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -32), |
| 146 | + ]) |
| 147 | + } |
| 148 | + |
| 149 | + |
12 | 150 | } |
0 commit comments