|
| 1 | +// |
| 2 | +// MenuChipCollectionViewCell.swift |
| 3 | +// EATSSU-DEV |
| 4 | +// |
| 5 | +// Created by 최지우 on 2/2/25. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | +import SnapKit |
| 10 | + |
| 11 | +import EATSSUDesign |
| 12 | + |
| 13 | +final class MenuChipCollectionViewCell: UICollectionViewCell { |
| 14 | + static let id = "MenuChipCollectionViewCell" |
| 15 | + |
| 16 | + private let menuChipView: UIView = { |
| 17 | + let view = UIView() |
| 18 | + view.backgroundColor = EATSSUDesignAsset.Color.Main.secondary.color |
| 19 | + view.layer.cornerRadius = 10 |
| 20 | + view.layer.borderColor = EATSSUDesignAsset.Color.Main.primary.color.cgColor |
| 21 | + view.layer.borderWidth = 0.5 |
| 22 | + view.backgroundColor = .purple |
| 23 | + return view |
| 24 | + }() |
| 25 | + |
| 26 | + private let thumbsupImageView: UIImageView = { |
| 27 | + let imageView = UIImageView(image: EATSSUDesignAsset.Images.thumbUp.image) |
| 28 | + imageView.contentMode = .scaleAspectFit |
| 29 | + return imageView |
| 30 | + }() |
| 31 | + |
| 32 | + private let menuLabel: UILabel = { |
| 33 | + let label = UILabel() |
| 34 | + label.font = EATSSUDesignFontFamily.Pretendard.medium.font(size: 10) |
| 35 | + label.textColor = EATSSUDesignAsset.Color.Main.primary.color |
| 36 | + label.text = "김치볶음바바바밥" |
| 37 | +// label.numberOfLines = 1 |
| 38 | +// label.sizeToFit() |
| 39 | +// label.frame.size = CGSize(width: CGFloat.greatestFiniteMagnitude, height: 22) |
| 40 | + return label |
| 41 | + }() |
| 42 | + |
| 43 | + lazy var menuChipStackView: UIStackView = { |
| 44 | + let stackView = UIStackView(arrangedSubviews: [thumbsupImageView, menuLabel]) |
| 45 | + stackView.axis = .horizontal |
| 46 | + stackView.spacing = 1 |
| 47 | +// stackView.backgroundColor = .green |
| 48 | + return stackView |
| 49 | + }() |
| 50 | + |
| 51 | + override init(frame: CGRect) { |
| 52 | + super.init(frame: frame) |
| 53 | + |
| 54 | + configureUI() |
| 55 | + setLayout() |
| 56 | + } |
| 57 | + |
| 58 | + required init?(coder: NSCoder) { |
| 59 | + fatalError("init(coder:) has not been implemented") |
| 60 | + } |
| 61 | + |
| 62 | + private func configureUI() { |
| 63 | + addSubview(menuChipView) |
| 64 | + menuChipView.addSubviews(menuChipStackView) |
| 65 | + } |
| 66 | + |
| 67 | + private func setLayout() { |
| 68 | + setupDynamicLayout() |
| 69 | + |
| 70 | +// menuChipStackView.snp.makeConstraints { make in |
| 71 | +// make.edges.equalToSuperview() |
| 72 | + |
| 73 | +// make.verticalEdges.equalToSuperview().inset(5) |
| 74 | +// make.horizontalEdges.equalToSuperview().inset(6) |
| 75 | +// } |
| 76 | +// menuChipView.snp.makeConstraints { make in |
| 77 | +// make.edges.equalToSuperview() |
| 78 | +// } |
| 79 | + thumbsupImageView.snp.makeConstraints { make in |
| 80 | + make.width.height.equalTo(10) |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + override func prepareForReuse() { |
| 86 | + super.prepareForReuse() |
| 87 | + self.prepare(name: nil) |
| 88 | + } |
| 89 | + func prepare(name: String?) { |
| 90 | + self.menuLabel.text = name |
| 91 | + setupDynamicLayout() |
| 92 | + } |
| 93 | + private func setupDynamicLayout() { |
| 94 | + menuLabel.sizeToFit() |
| 95 | + let viewSize = menuLabel.intrinsicContentSize |
| 96 | + let width = viewSize.width + 58 |
| 97 | + let height = viewSize.height + 48 |
| 98 | + |
| 99 | + menuChipView.snp.remakeConstraints { make in |
| 100 | + make.width.equalTo(width) |
| 101 | + make.height.equalTo(height) |
| 102 | + } |
| 103 | + |
| 104 | + menuChipStackView.snp.remakeConstraints { make in |
| 105 | + make.width.equalTo(width) |
| 106 | + make.height.equalTo(height) |
| 107 | + } |
| 108 | + |
| 109 | + layoutIfNeeded() |
| 110 | + } |
| 111 | + |
| 112 | +// private func setupDynamicLayout() { |
| 113 | +// menuLabel.sizeToFit() |
| 114 | +// let viewSize = menuLabel.intrinsicContentSize |
| 115 | +// let width = viewSize.width + 58 |
| 116 | +// let height = viewSize.height + 48 |
| 117 | +//// menuChipStackView.frame.size = CGSize(width: width, height: height) |
| 118 | +// menuChipStackView.frame.size = CGSize(width: width, height: height) |
| 119 | +// menuChipView.frame.size = CGSize(width: width, height: height) |
| 120 | +// |
| 121 | +//// menuChipStackView.center = CGPoint(x: width / 2, y: height / 2) |
| 122 | +// } |
| 123 | + |
| 124 | +} |
0 commit comments