forked from Runnect/Runnect-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Runnect#54 - CourseDiscoveryVC UI 수정(섹션셀구현)
- Loading branch information
1 parent
3edd1aa
commit 1a196a0
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Reuse/AdImageCollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// AdImageCollectionViewCell.swift | ||
// Runnect-iOS | ||
// | ||
// Created by YEONOO on 2023/01/10. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
import Then | ||
|
||
class AdImageCollectionViewCell: UICollectionViewCell { | ||
|
||
// MARK: - Identifier | ||
static let identifier = "AdImageCollectionViewCell" | ||
// MARK: - UI Components | ||
private let adImageView = UIImageView().then { | ||
$0.image = UIImage(named: "adimage") | ||
} | ||
// MARK: - Life cycle | ||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
layout() | ||
} | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
// MARK: - Extensions | ||
|
||
extension AdImageCollectionViewCell { | ||
|
||
// MARK: - Layout Helpers | ||
|
||
func layout() { | ||
contentView.backgroundColor = .clear | ||
contentView.addSubview(adImageView) | ||
adImageView.snp.makeConstraints { | ||
$0.top.equalToSuperview() | ||
$0.leading.trailing.equalTo(self.contentView.safeAreaLayoutGuide) | ||
$0.height.equalTo(183) | ||
} | ||
|
||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Reuse/CollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// CollectionViewCell.swift | ||
// Runnect-iOS | ||
// | ||
// Created by YEONOO on 2023/01/10. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
import Then | ||
|
||
class CollectionViewCell: UICollectionViewCell { | ||
|
||
// MARK: - Identifier | ||
static let identifier = "CollectionViewCell" | ||
// MARK: - collectionview | ||
private lazy var mapCollectionView: UICollectionView = { | ||
let layout = UICollectionViewFlowLayout() | ||
layout.scrollDirection = .vertical | ||
|
||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) | ||
collectionView.backgroundColor = .clear | ||
collectionView.translatesAutoresizingMaskIntoConstraints = false | ||
collectionView.isScrollEnabled = false | ||
collectionView.showsVerticalScrollIndicator = false | ||
return collectionView | ||
}() | ||
// MARK: - Constants | ||
|
||
final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16) | ||
final let itemSpacing: CGFloat = 10 | ||
final let lineSpacing: CGFloat = 20 | ||
|
||
// MARK: - Life cycle | ||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
layout() | ||
register() | ||
setDelegate() | ||
layout() | ||
} | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
extension CollectionViewCell { | ||
|
||
private func setDelegate() { | ||
mapCollectionView.delegate = self | ||
mapCollectionView.dataSource = self | ||
} | ||
private func register() { | ||
mapCollectionView.register(CourseListCVC.self, | ||
forCellWithReuseIdentifier: CourseListCVC.className) | ||
} | ||
} | ||
// MARK: - Extensions | ||
|
||
extension CollectionViewCell { | ||
|
||
// MARK: - Layout Helpers | ||
|
||
func layout() { | ||
contentView.backgroundColor = .clear | ||
contentView.addSubview(mapCollectionView) | ||
mapCollectionView.snp.makeConstraints { | ||
$0.top.equalToSuperview() | ||
$0.leading.trailing.equalTo(contentView.safeAreaLayoutGuide) | ||
$0.bottom.equalToSuperview() | ||
$0.height.equalTo(1000) | ||
} | ||
} | ||
} | ||
// MARK: - UICollectionViewDelegate, UICollectionViewDataSource | ||
|
||
extension CollectionViewCell: UICollectionViewDelegate, UICollectionViewDataSource { | ||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return 15 | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseListCVC.className, | ||
for: indexPath) | ||
as? CourseListCVC else { return UICollectionViewCell() } | ||
cell.setCellType(type: .all) | ||
return cell | ||
} | ||
} | ||
|
||
// MARK: - UICollectionViewDelegateFlowLayout | ||
|
||
extension CollectionViewCell: UICollectionViewDelegateFlowLayout { | ||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
let cellWidth = (UIScreen.main.bounds.width - (self.itemSpacing + 2*self.collectionViewInset.left)) / 2 | ||
let cellHeight = CourseListCVCType.getCellHeight(type: .all, cellWidth: cellWidth) | ||
|
||
return CGSize(width: cellWidth, height: cellHeight) | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { | ||
return self.collectionViewInset | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { | ||
return self.itemSpacing | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { | ||
return self.lineSpacing | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
Runnect-iOS/Runnect-iOS/Presentation/CourseDiscovery/Reuse/TitleCollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// TitleCollectionViewCell.swift | ||
// Runnect-iOS | ||
// | ||
// Created by YEONOO on 2023/01/10. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
import Then | ||
|
||
class TitleCollectionViewCell: UICollectionViewCell { | ||
|
||
// MARK: - Identifier | ||
static let identifier = "TitleCollectionViewCell" | ||
// MARK: - UI Components | ||
private let titleView = UIView() | ||
private let mainLabel: UILabel = { | ||
let label = UILabel() | ||
label.text = "코스 추천" | ||
label.font = UIFont.h4 | ||
label.textColor = UIColor.g1 | ||
return label | ||
}() | ||
private let subLabel: UILabel = { | ||
let label = UILabel() | ||
label.text = "새로운 코스를 발견해나가요" | ||
label.font = UIFont.b6 | ||
label.textColor = UIColor.g1 | ||
return label | ||
}() | ||
|
||
// MARK: - Life cycle | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
layout() | ||
} | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
// MARK: - Extensions | ||
|
||
extension TitleCollectionViewCell { | ||
|
||
// MARK: - Layout Helpers | ||
|
||
func layout() { | ||
contentView.backgroundColor = .clear | ||
contentView.addSubview(titleView) | ||
|
||
titleView.addSubviews(mainLabel, subLabel) | ||
mainLabel.snp.makeConstraints { | ||
$0.top.equalToSuperview().offset(9) | ||
$0.leading.equalToSuperview().offset(16) | ||
} | ||
subLabel.snp.makeConstraints { | ||
$0.top.equalTo(self.mainLabel.snp.bottom).offset(4) | ||
$0.leading.equalToSuperview().offset(16) | ||
} | ||
} | ||
} |