|
| 1 | +// |
| 2 | +// ThumbsCountView.swift |
| 3 | +// EATSSU |
| 4 | +// |
| 5 | +// Created by 최지우 on 2/18/25. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | + |
| 10 | +import EATSSUDesign |
| 11 | +import SnapKit |
| 12 | + |
| 13 | +enum ThumbType { |
| 14 | + case up |
| 15 | + case down |
| 16 | +} |
| 17 | + |
| 18 | +final class ThumbsCountView: BaseUIView { |
| 19 | + |
| 20 | + // MARK: - Properties |
| 21 | + |
| 22 | + private let thumbType: ThumbType |
| 23 | + |
| 24 | + // MARK: - UI Components |
| 25 | + |
| 26 | + private let thumbImageView: UIImageView = { |
| 27 | + let imageView = UIImageView() |
| 28 | + imageView.contentMode = .scaleAspectFit |
| 29 | + return imageView |
| 30 | + }() |
| 31 | + |
| 32 | + private let countLabel: UILabel = { |
| 33 | + let label = UILabel() |
| 34 | + label.font = EATSSUDesignFontFamily.Pretendard.semiBold.font(size: 16) |
| 35 | + label.text = "12" |
| 36 | + return label |
| 37 | + }() |
| 38 | + |
| 39 | + // MARK: - Functions |
| 40 | + |
| 41 | + init(thumbType: ThumbType) { |
| 42 | + self.thumbType = thumbType |
| 43 | + super.init(frame: .zero) |
| 44 | + setThumbImage() |
| 45 | + } |
| 46 | + |
| 47 | + override func configureUI() { |
| 48 | + addSubviews(thumbImageView, |
| 49 | + countLabel) |
| 50 | + } |
| 51 | + |
| 52 | + override func setLayout() { |
| 53 | + thumbImageView.snp.makeConstraints { make in |
| 54 | + make.height.width.equalTo(16) |
| 55 | + make.top.leading.equalToSuperview() |
| 56 | + } |
| 57 | + countLabel.snp.makeConstraints { make in |
| 58 | + make.top.trailing.equalToSuperview() |
| 59 | + make.leading.equalTo(thumbImageView.snp.trailing).offset(11) |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private func setThumbImage() { |
| 64 | + switch thumbType { |
| 65 | + case .up: |
| 66 | + thumbImageView.image = EATSSUDesignAsset.Images.filledThumbUp.image |
| 67 | + case .down: |
| 68 | + thumbImageView.image = EATSSUDesignAsset.Images.filledThumbDown.image |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + public func updateCount(thumbCnt: Int) { |
| 73 | + countLabel.text = "\(thumbCnt)" |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments