Skip to content

Commit 23b4b0c

Browse files
committed
Adding View MenuItemCell
1 parent 1decc9b commit 23b4b0c

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// MenuItemCell.swift
3+
// DeliveryApp
4+
//
5+
// Created by Manoel Filho on 21/07/22.
6+
//
7+
8+
import UIKit
9+
10+
final class MenuItemCell: UIView {
11+
12+
var menuItem: MenuItem? {
13+
didSet{
14+
self.nameLabel.text = menuItem?.name
15+
self.priceLabel.text = .currencyValue(value: menuItem?.price ?? 0)
16+
self.productImage.image = UIImage(named: "pizza")
17+
}
18+
}
19+
20+
private lazy var wrapperItemStackView: UIStackView = {
21+
let wrapperItemStackView = UIStackView()
22+
wrapperItemStackView.alignment = .center
23+
wrapperItemStackView.translatesAutoresizingMaskIntoConstraints = false
24+
return wrapperItemStackView
25+
}()
26+
27+
private lazy var descriptionItemStackView: UIStackView = {
28+
let descriptionItemStackView = UIStackView()
29+
descriptionItemStackView.axis = .vertical
30+
descriptionItemStackView.spacing = 5
31+
descriptionItemStackView.translatesAutoresizingMaskIntoConstraints = false
32+
return descriptionItemStackView
33+
}()
34+
35+
private lazy var nameLabel: UILabel = {
36+
let nameLabel = UILabel()
37+
nameLabel.text = "Title"
38+
nameLabel.font = .systemFont(ofSize: 15, weight: .medium)
39+
nameLabel.tintColor = .black
40+
nameLabel.translatesAutoresizingMaskIntoConstraints = false
41+
return nameLabel
42+
}()
43+
44+
45+
private lazy var priceLabel: UILabel = {
46+
let priceLabel = UILabel()
47+
priceLabel.text = "0"
48+
priceLabel.font = .systemFont(ofSize: 13, weight: .regular)
49+
priceLabel.tintColor = .gray
50+
priceLabel.translatesAutoresizingMaskIntoConstraints = false
51+
return priceLabel
52+
}()
53+
54+
private lazy var productImage: UIImageView = {
55+
let productImage = UIImageView()
56+
productImage.translatesAutoresizingMaskIntoConstraints = false
57+
productImage.clipsToBounds = true
58+
productImage.contentMode = .scaleAspectFill
59+
productImage.layer.cornerRadius = 10
60+
return productImage
61+
}()
62+
63+
convenience init() {
64+
self.init(frame: .zero)
65+
setup()
66+
}
67+
68+
}
69+
70+
71+
extension MenuItemCell: ViewCode {
72+
73+
func setupSubviews() {
74+
75+
descriptionItemStackView.addArrangedSubview(nameLabel)
76+
descriptionItemStackView.addArrangedSubview(priceLabel)
77+
78+
wrapperItemStackView.addArrangedSubview(descriptionItemStackView)
79+
wrapperItemStackView.addArrangedSubview(productImage)
80+
81+
addSubview(wrapperItemStackView)
82+
}
83+
84+
func setupConstraints() {
85+
setupStacksConstraints()
86+
setupImagesConstraints()
87+
}
88+
89+
private func setupImagesConstraints() {
90+
let sizeImage = CGSize(width: 65, height: 65)
91+
NSLayoutConstraint.activate([
92+
productImage.widthAnchor.constraint(equalToConstant: sizeImage.width),
93+
productImage.heightAnchor.constraint(equalToConstant: sizeImage.height)
94+
])
95+
}
96+
97+
private func setupStacksConstraints() {
98+
NSLayoutConstraint.activate([
99+
wrapperItemStackView.topAnchor.constraint(equalTo: topAnchor),
100+
wrapperItemStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
101+
wrapperItemStackView.bottomAnchor.constraint(equalTo: bottomAnchor),
102+
wrapperItemStackView.trailingAnchor.constraint(equalTo: trailingAnchor)
103+
])
104+
}
105+
106+
}

0 commit comments

Comments
 (0)