Skip to content

Commit

Permalink
Merge pull request #87 from Drink-Easy/DY
Browse files Browse the repository at this point in the history
#85 와인클래스 메인 화면 작업
  • Loading branch information
doyeonk429 authored Oct 30, 2024
2 parents 71fc694 + cc5f42b commit cba6520
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 18 deletions.
110 changes: 103 additions & 7 deletions Drink-EG/Drink-EG/Sources/Cells/WineClass/NewWineClassCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,118 @@ 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
imageView.layer.cornerRadius = 10
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 {
Expand Down Expand Up @@ -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` 값 변경 시 레이어 업데이트
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit cba6520

Please sign in to comment.