Skip to content

Commit

Permalink
#43 Feat : 카드 뷰 제작 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
doyeonk429 committed Aug 16, 2024
1 parent 7cd155b commit 23b6286
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 171 deletions.
32 changes: 32 additions & 0 deletions Drink-EG/Drink-EG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
165401112C6E2B79008A9DBF /* WineNewsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165401102C6E2B79008A9DBF /* WineNewsViewController.swift */; };
165401132C6E2BAA008A9DBF /* WineKnowledgeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165401122C6E2BAA008A9DBF /* WineKnowledgeViewController.swift */; };
165401162C6E3858008A9DBF /* CardSlider in Frameworks */ = {isa = PBXBuildFile; productRef = 165401152C6E3858008A9DBF /* CardSlider */; };
165401192C6E555A008A9DBF /* CardSliderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165401182C6E555A008A9DBF /* CardSliderViewController.swift */; };
1654011B2C6E5661008A9DBF /* CardTitleview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1654011A2C6E5661008A9DBF /* CardTitleview.swift */; };
1654011D2C6E5681008A9DBF /* CardsLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1654011C2C6E5681008A9DBF /* CardsLayout.swift */; };
1654011F2C6E56A9008A9DBF /* UIViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1654011E2C6E56A9008A9DBF /* UIViewExtension.swift */; };
165401212C6E56BD008A9DBF /* RatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165401202C6E56BD008A9DBF /* RatingView.swift */; };
165401232C6E57BC008A9DBF /* CardSliderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165401222C6E57BC008A9DBF /* CardSliderCell.swift */; };
16752F9D2C5A7FB90001907D /* HexCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16752F9C2C5A7FB90001907D /* HexCode.swift */; };
16B97CD42C4BEB0900D8B453 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16B97CD32C4BEB0900D8B453 /* AppDelegate.swift */; };
16B97CD62C4BEB0900D8B453 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16B97CD52C4BEB0900D8B453 /* SceneDelegate.swift */; };
Expand Down Expand Up @@ -136,6 +142,12 @@
1654010E2C6E2B4B008A9DBF /* MyCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCollectionViewController.swift; sourceTree = "<group>"; };
165401102C6E2B79008A9DBF /* WineNewsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WineNewsViewController.swift; sourceTree = "<group>"; };
165401122C6E2BAA008A9DBF /* WineKnowledgeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WineKnowledgeViewController.swift; sourceTree = "<group>"; };
165401182C6E555A008A9DBF /* CardSliderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardSliderViewController.swift; path = ../../../../../../../../Downloads/CardSliderViewController.swift; sourceTree = "<group>"; };
1654011A2C6E5661008A9DBF /* CardTitleview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardTitleview.swift; path = ../../../../../../../../Downloads/CardTitleview.swift; sourceTree = "<group>"; };
1654011C2C6E5681008A9DBF /* CardsLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardsLayout.swift; path = ../../../../../../../../Downloads/CardsLayout.swift; sourceTree = "<group>"; };
1654011E2C6E56A9008A9DBF /* UIViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIViewExtension.swift; path = ../../../../../../../../Downloads/UIViewExtension.swift; sourceTree = "<group>"; };
165401202C6E56BD008A9DBF /* RatingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RatingView.swift; path = ../../../../../../../../Downloads/RatingView.swift; sourceTree = "<group>"; };
165401222C6E57BC008A9DBF /* CardSliderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CardSliderCell.swift; path = ../../../../../../../../Downloads/CardSliderCell.swift; sourceTree = "<group>"; };
16752F9C2C5A7FB90001907D /* HexCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexCode.swift; sourceTree = "<group>"; };
16B97CD02C4BEB0900D8B453 /* Drink-EG.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Drink-EG.app"; sourceTree = BUILT_PRODUCTS_DIR; };
16B97CD32C4BEB0900D8B453 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +279,19 @@
path = APIResponseModels;
sourceTree = "<group>";
};
165401172C6E5545008A9DBF /* CustomCardSlider */ = {
isa = PBXGroup;
children = (
165401182C6E555A008A9DBF /* CardSliderViewController.swift */,
1654011A2C6E5661008A9DBF /* CardTitleview.swift */,
1654011C2C6E5681008A9DBF /* CardsLayout.swift */,
1654011E2C6E56A9008A9DBF /* UIViewExtension.swift */,
165401202C6E56BD008A9DBF /* RatingView.swift */,
165401222C6E57BC008A9DBF /* CardSliderCell.swift */,
);
path = CustomCardSlider;
sourceTree = "<group>";
};
16B97CC72C4BEB0900D8B453 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -392,6 +417,7 @@
16B97CF32C4BF40100D8B453 /* Protocols */ = {
isa = PBXGroup;
children = (
165401172C6E5545008A9DBF /* CustomCardSlider */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -625,7 +651,9 @@
5E2219552C69D5E7005849FB /* CustomSlider.swift in Sources */,
1654010B2C6BACDC008A9DBF /* SelectionManager.swift in Sources */,
16752F9D2C5A7FB90001907D /* HexCode.swift in Sources */,
165401192C6E555A008A9DBF /* CardSliderViewController.swift in Sources */,
1F598F0B2C5CBD9E000CE79F /* EnterTasteTestViewController.swift in Sources */,
165401212C6E56BD008A9DBF /* RatingView.swift in Sources */,
5E22196E2C6B2EA0005849FB /* RatingViewController.swift in Sources */,
1F205A432C6B66EB00E80659 /* TasteTestThirdCollectionViewCell.swift in Sources */,
5E23147F2C5901BB004E2013 /* (null) in Sources */,
Expand All @@ -639,11 +667,15 @@
1F598EFD2C58150E000CE79F /* JoinViewController.swift in Sources */,
165400E32C69D6B9008A9DBF /* CallMoyaExample.swift in Sources */,
165400E72C69DDBE008A9DBF /* TastingNoteAPI.swift in Sources */,
1654011F2C6E56A9008A9DBF /* UIViewExtension.swift in Sources */,
1654010F2C6E2B4B008A9DBF /* MyCollectionViewController.swift in Sources */,
1654011D2C6E5681008A9DBF /* CardsLayout.swift in Sources */,
16B97CEC2C4BF37E00D8B453 /* Constant.swift in Sources */,
16B97D182C4C0F6E00D8B453 /* SearchVideoViewController.swift in Sources */,
1F598EEC2C524D2E000CE79F /* RecomCollectionViewCell.swift in Sources */,
165401232C6E57BC008A9DBF /* CardSliderCell.swift in Sources */,
1654010D2C6C7FBB008A9DBF /* APIResponseMemberResponse.swift in Sources */,
1654011B2C6E5661008A9DBF /* CardTitleview.swift in Sources */,
165401072C6BA5D8008A9DBF /* MemberInfoRequest.swift in Sources */,
1F205A372C6A71BC00E80659 /* APIResponseLoginResponse.swift in Sources */,
165400FA2C69F15D008A9DBF /* APIResponseWineNewsResponse.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,188 +8,36 @@
import UIKit
import SnapKit

class WineClassMainViewController : UIViewController {

// "VINO 클래스" 타이틀
private let titleLabel: UILabel = {
let label = UILabel()
label.text = "VINO 클래스"
label.font = UIFont.boldSystemFont(ofSize: 28)
label.textColor = .black
return label
}()

// 검색창
private let searchBar: UISearchBar = {
let searchBar = UISearchBar()
searchBar.placeholder = "제목, 연관내용 검색"
searchBar.backgroundImage = UIImage() // 배경을 없앰
return searchBar
}()

// "내 보관함" 버튼
private let myCollectionButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("내 보관함", for: .normal)
button.setTitleColor(.black, for: .normal)
button.backgroundColor = UIColor.white
button.layer.cornerRadius = 15
button.addTarget(WineClassMainViewController.self, action: #selector(didTapMyCollectionButton), for: .touchUpInside)
return button
}()



// "15초만에 알아가는 와인 지식" 카드 뷰
private let wineKnowledgeCardView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 10
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 0.1
view.layer.shadowOffset = CGSize(width: 0, height: 2)
view.layer.shadowRadius = 4
let tapGesture = UITapGestureRecognizer(target: WineClassMainViewController.self, action: #selector(didTapWineKnowledgeCard))
view.addGestureRecognizer(tapGesture)
view.isUserInteractionEnabled = true
return view
}()

// 카드 이미지뷰
private let cardImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "ClassSampleImage"))
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 10
imageView.layer.masksToBounds = true
return imageView
}()

// "15초만에 알아가는 와인 지식" 라벨
private let wineKnowledgeLabel: UILabel = {
let label = UILabel()
label.text = "15초만에 알아가는 와인 지식"
label.font = UIFont.systemFont(ofSize: 20, weight: .bold)
label.textColor = .black
return label
}()

// "이번 달 와인뉴스" 카드 뷰
private let wineNewsCardView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 10
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 0.1
view.layer.shadowOffset = CGSize(width: 0, height: 2)
view.layer.shadowRadius = 4
let tapGesture = UITapGestureRecognizer(target: WineClassMainViewController.self, action: #selector(didTapWineNewsCard))
view.addGestureRecognizer(tapGesture)
view.isUserInteractionEnabled = true
return view
}()

// "이번 달 와인뉴스" 카드 이미지뷰
private let newsImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "ClassSampleImage"))
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 10
imageView.layer.masksToBounds = true
return imageView
}()

// "이번 달 와인뉴스" 라벨
private let wineNewsLabel: UILabel = {
let label = UILabel()
label.text = "이번 달 와인뉴스"
label.font = UIFont.systemFont(ofSize: 20, weight: .bold)
label.textColor = .black
return label
}()
struct Item: CardSliderItem {
var image: UIImage
var rating: Int?
var title: String
var subtitle: String?
var description: String?
}

class WineClassMainViewController : CardSliderViewController, CardSliderDataSource {
var datas = [Item]()

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white
setupUI()
}
datas.append(Item(image: UIImage(named: "ClassSampleImage")!, title: "First Wine Class"))
datas.append(Item(image: UIImage(named: "ClassSampleImage")!, title: "Second Wine Class"))
datas.append(Item(image: UIImage(named: "ClassSampleImage")!, title: "Third Wine Class"))

private func setupUI() {
// Add subviews
view.addSubview(titleLabel)
view.addSubview(searchBar)
view.addSubview(wineKnowledgeCardView)
view.addSubview(myCollectionButton)
view.addSubview(wineNewsCardView)

wineKnowledgeCardView.addSubview(cardImageView)
wineKnowledgeCardView.addSubview(wineKnowledgeLabel)

wineNewsCardView.addSubview(newsImageView)
wineNewsCardView.addSubview(wineNewsLabel)

// Layout constraints using SnapKit
titleLabel.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide).offset(20)
make.leading.equalToSuperview().offset(16)
}

searchBar.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(10)
make.leading.trailing.equalToSuperview().inset(16)
}

wineKnowledgeCardView.snp.makeConstraints { make in
make.top.equalTo(searchBar.snp.bottom).offset(20)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(200)
}

cardImageView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

wineKnowledgeLabel.snp.makeConstraints { make in
make.bottom.equalToSuperview().inset(10)
make.leading.equalToSuperview().offset(10)
}

myCollectionButton.snp.makeConstraints { make in
make.trailing.equalTo(wineKnowledgeCardView.snp.trailing).inset(16)
make.centerY.equalTo(wineKnowledgeCardView.snp.centerY)
make.height.equalTo(30)
make.width.equalTo(100)
}

wineNewsCardView.snp.makeConstraints { make in
make.top.equalTo(wineKnowledgeCardView.snp.bottom).offset(40)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(200)
}
view.backgroundColor = .white

newsImageView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
self.dataSource = self

wineNewsLabel.snp.makeConstraints { make in
make.bottom.equalToSuperview().inset(10)
make.leading.equalToSuperview().offset(10)
}
}

// MARK: - Actions

@objc private func didTapMyCollectionButton() {
let myCollectionViewController = MyCollectionViewController()
navigationController?.pushViewController(myCollectionViewController, animated: true)
func item(for index: Int) -> any CardSliderItem {
datas[index]
}

@objc private func didTapWineKnowledgeCard() {
let wineKnowledgeViewController = WineKnowledgeViewController()
navigationController?.pushViewController(wineKnowledgeViewController, animated: true)
func numberOfItems() -> Int {
datas.count
}

@objc private func didTapWineNewsCard() {
let wineNewsViewController = WineNewsViewController()
navigationController?.pushViewController(wineNewsViewController, animated: true)
}
}

0 comments on commit 23b6286

Please sign in to comment.