diff --git a/Drink-EG/Drink-EG/Sources/Cells/WineClass/NewWineClassCell.swift b/Drink-EG/Drink-EG/Sources/Cells/WineClass/NewWineClassCell.swift index fb3ebe4..8b52c11 100644 --- a/Drink-EG/Drink-EG/Sources/Cells/WineClass/NewWineClassCell.swift +++ b/Drink-EG/Drink-EG/Sources/Cells/WineClass/NewWineClassCell.swift @@ -9,7 +9,10 @@ import UIKit class NewWineClassCell: UITableViewCell { - private let wineImageView: UIImageView = { + private let containerView = UIView() + private let progressView = UIView() + + private let classImageView: UIImageView = { let imageView = UIImageView() imageView.contentMode = .scaleAspectFill imageView.clipsToBounds = true @@ -17,30 +20,107 @@ class NewWineClassCell: UITableViewCell { return imageView }() - private let wineNameLabel: UILabel = { + private let classNameLabel: UILabel = { let label = UILabel() label.font = UIFont.ptdBoldFont(ofSize: 16) label.textColor = .black return label }() - private let wineProgressView: GradientProgressView = { + private let classProgressbarView: GradientProgressView = { let progressView = GradientProgressView(progressViewStyle: .default) progressView.progressTintColor = .clear // progress 자체 색상은 비우고 gradient로 설정 return progressView }() - + + private let progressLabel: UILabel = { + let label = UILabel() + label.font = UIFont.ptdRegularFont(ofSize: 12) + label.textColor = UIColor(hex: "#7E13B1") + return label + }() + override func awakeFromNib() { super.awakeFromNib() // Initialization code } - + + private func setupViews() { + contentView.addSubview(classImageView) + contentView.addSubview(containerView) + + containerView.addSubview(classNameLabel) + containerView.addSubview(progressView) + + progressView.addSubview(classProgressbarView) + progressView.addSubview(progressLabel) + } + + private func setupConstraints() { + classImageView.snp.makeConstraints { make in + make.top.equalToSuperview().offset(10) + make.leading.equalToSuperview().offset(10) + make.width.equalToSuperview().multipliedBy(0.25) + make.height.equalTo(classImageView.snp.width).multipliedBy(10.0 / 9.0) + make.bottom.lessThanOrEqualToSuperview().offset(-10) // 하단 여백 추가 + } + + containerView.snp.makeConstraints { make in + make.top.equalTo(classImageView) + make.bottom.equalToSuperview().offset(-10) + make.leading.equalTo(classImageView.snp.trailing).offset(16) + make.trailing.equalToSuperview().offset(-10) + } + + classNameLabel.snp.makeConstraints { make in + make.top.equalToSuperview().offset(10) + make.leading.trailing.equalToSuperview() + } + + progressView.snp.makeConstraints { make in + make.leading.trailing.equalToSuperview() + make.top.greaterThanOrEqualTo(classNameLabel.snp.bottom).offset(10) + make.bottom.equalToSuperview().offset(-16) + } + + classProgressbarView.snp.makeConstraints { make in + make.leading.equalToSuperview().offset(10) + make.trailing.equalToSuperview().offset(-10) + make.top.equalToSuperview() + make.height.equalTo(4) + } + + progressLabel.snp.makeConstraints { make in + make.trailing.equalToSuperview().offset(-10) + make.top.greaterThanOrEqualTo(classProgressbarView.snp.bottom).offset(8) + make.bottom.equalToSuperview().offset(-8) + } + } + + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setupViews() + setupConstraints() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public func configure(with image: UIImage?, name: String, progress: Float) { + classImageView.image = image + classNameLabel.text = name + classProgressbarView.progress = progress + progressLabel.text = String(format: "%.1f%%", progress * 100) + } + override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) - + // Configure the view for the selected state } - + } class GradientProgressView: UIProgressView { @@ -79,4 +159,20 @@ class GradientProgressView: UIProgressView { // gradientLayer가 progress보다 앞쪽에 표시되도록 설정 gradientLayer.mask = layer.sublayers?.first } + + private func updateGradientLayerFrame() { + // `progress` 값을 기반으로 `gradientLayer`의 폭을 조절 + gradientLayer.frame = CGRect( + x: 0, + y: 0, + width: bounds.width * CGFloat(progress), + height: bounds.height + ) + } + + override var progress: Float { + didSet { + updateGradientLayerFrame() // `progress` 값 변경 시 레이어 업데이트 + } + } } diff --git a/Drink-EG/Drink-EG/Sources/VCs/NewWineClass/ClassSelectionViewController.swift b/Drink-EG/Drink-EG/Sources/VCs/NewWineClass/ClassSelectionViewController.swift index 13611ed..9b4e452 100644 --- a/Drink-EG/Drink-EG/Sources/VCs/NewWineClass/ClassSelectionViewController.swift +++ b/Drink-EG/Drink-EG/Sources/VCs/NewWineClass/ClassSelectionViewController.swift @@ -17,12 +17,36 @@ class ClassSelectionViewController: UIViewController, UICollectionViewDelegate, private var selectedIndexPath = IndexPath(item: 0, section: 0) // 더미 데이터 (각 탭에 대한 테이블 뷰 데이터) - private let tableViewData: [[String]] = [ - ["Item 1", "Item 2", "Item 3"], - ["Red Wine 1", "Red Wine 2", "Red Wine 3"], - ["White Wine 1", "White Wine 2", "White Wine 3"], - ["Sparkling Wine 1", "Sparkling Wine 2", "Sparkling Wine 3"], - ["Other 1", "Other 2", "Other 3"] + private let totalClassData = [ + [ + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_1", progress: 0.7), + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_2", progress: 0.2), + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_3", progress: 0.0), + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas1", progress: 0.7), + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas2", progress: 0.5), + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas3", progress: 0.3), + + ], + [ + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_1", progress: 0.7), + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_2", progress: 0.2), + (image: UIImage(named: "Red Label"), name: "[레드] Red Label_3", progress: 0.0) + ], + [ + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas1", progress: 0.7), + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas2", progress: 0.5), + (image: UIImage(named: "Dos Copas"), name: "[화이트] Dos Copas3", progress: 0.3) + ], + [ + (image: UIImage(named: "Red Label"), name: "[스파클링] Red Label_1", progress: 0.7), + (image: UIImage(named: "Red Label"), name: "[스파클링] Red Label_2", progress: 0.2), + (image: UIImage(named: "Red Label"), name: "[스파클링] Red Label_3", progress: 0.0) + ], + [ + (image: UIImage(named: "Dos Copas"), name: "[기타] Dos Copas1", progress: 0.7), + (image: UIImage(named: "Dos Copas"), name: "[기타] Dos Copas2", progress: 0.5), + (image: UIImage(named: "Dos Copas"), name: "[기타] Dos Copas3", progress: 0.3) + ] ] private let searchBarView = SearchBarView() @@ -49,7 +73,7 @@ class ClassSelectionViewController: UIViewController, UICollectionViewDelegate, // 테이블 뷰 private let tableView = UITableView().then { - $0.register(UITableViewCell.self, forCellReuseIdentifier: "TableViewCell") + $0.register(NewWineClassCell.self, forCellReuseIdentifier: "NewWineClassCell") } override func viewDidLoad() { @@ -113,7 +137,7 @@ class ClassSelectionViewController: UIViewController, UICollectionViewDelegate, // 테이블 뷰 레이아웃 설정 tableView.snp.makeConstraints { make in - make.top.equalTo(indicatorView.snp.bottom) + make.top.equalTo(indicatorView.snp.bottom).offset(10) make.left.equalTo(searchBarView.snp.left) make.right.equalTo(searchBarView.snp.right) make.bottom.equalToSuperview() @@ -183,12 +207,15 @@ class ClassSelectionViewController: UIViewController, UICollectionViewDelegate, // MARK: - TableView DataSource & Delegate func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return tableViewData[selectedIndexPath.item].count + return totalClassData[selectedIndexPath.item].count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) - cell.textLabel?.text = tableViewData[selectedIndexPath.item][indexPath.row] + guard let cell = tableView.dequeueReusableCell(withIdentifier: "NewWineClassCell", for: indexPath) as? NewWineClassCell else { return UITableViewCell() } + + let wineData = totalClassData[selectedIndexPath.item][indexPath.row] + cell.configure(with: wineData.image, name: wineData.name, progress: Float(wineData.progress)) + return cell } }