Skip to content

Commit

Permalink
Merge pull request #419 from TeamNado-Sunbae/feature/#415-Home-TableV…
Browse files Browse the repository at this point in the history
…iew-UI
  • Loading branch information
dev-jungbin authored Aug 7, 2022
2 parents 0c939c5 + e0142d0 commit 2e1778f
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// HomeFooterCell.swift
// NadoSunbae
//
// Created by madilyn on 2022/08/05.
//

import UIKit

class HomeFooterCell: UITableViewCell {

// MARK: - Initialization
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
configureUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

// MARK: - UI
extension HomeFooterCell {
private func configureUI() {
tintColor = .clear
backgroundColor = .gray0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// HomeBannerHeaderCell.swift
// NadoSunbae
//
// Created by madilyn on 2022/08/05.
//

import UIKit

class HomeBannerHeaderCell: UITableViewCell {

// MARK: Components
private let logoImgView = UIImageView().then {
$0.image = UIImage(named: "logoLogin")
$0.contentMode = .scaleAspectFill
}
private let univLabel = UILabel().then {
$0.textAlignment = .right
$0.font = .PretendardM(size: 14)
$0.textColor = .gray4
$0.text = "고려대학교"
}

// MARK: - Initialization
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
configureUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

// MARK: - UI
extension HomeBannerHeaderCell {
private func configureUI() {
tintColor = .white
backgroundColor = .white

addSubviews([logoImgView, univLabel])

logoImgView.snp.makeConstraints {
$0.left.equalToSuperview().inset(20)
$0.centerY.equalToSuperview()
$0.width.equalTo(82.adjusted)
$0.height.equalTo(28.adjusted)
}

univLabel.snp.makeConstraints {
$0.right.equalToSuperview().inset(20)
$0.centerY.equalToSuperview()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// HomeTitleHeaderCell.swift
// NadoSunbae
//
// Created by madilyn on 2022/08/05.
//

import UIKit

class HomeTitleHeaderCell: UITableViewCell {

// MARK: Components
private let titleLabel = UILabel().then {
$0.font = .PretendardB(size: 18)
$0.textColor = .mainBlack
}

// MARK: - Initialization
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
configureUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setTitleLabel(titleText: String) {
titleLabel.text = titleText
titleLabel.sizeToFit()
}
}

// MARK: - UI
extension HomeTitleHeaderCell {
private func configureUI() {
tintColor = .white
backgroundColor = .white

addSubviews([titleLabel])

titleLabel.snp.makeConstraints {
$0.top.equalToSuperview().inset(40)
$0.left.equalToSuperview().inset(24)
}
}
}
136 changes: 129 additions & 7 deletions NadoSunbae-iOS/NadoSunbae-iOS/Screen/Home/VC/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,149 @@ import SnapKit
import Then

class HomeVC: BaseVC {

// MARK: Components
private var tabLabel = UILabel().then {
$0.text = ""
private var backgroundTV = UITableView().then {
$0.separatorStyle = .none
$0.backgroundColor = .white
}


// MARK: - Properties
enum HomeBackgroundTVSectionType: Int {
case banner = 0, review, questionPerson, community
}

// MARK: Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureUI()
setBackgroundTV()
}

private func setBackgroundTV() {
backgroundTV.dataSource = self
backgroundTV.delegate = self

backgroundTV.sectionHeaderTopPadding = 0

backgroundTV.register(HomeBannerHeaderCell.self, forCellReuseIdentifier: HomeBannerHeaderCell.className)
backgroundTV.register(HomeTitleHeaderCell.self, forCellReuseIdentifier: HomeTitleHeaderCell.className)
backgroundTV.register(HomeFooterCell.self, forCellReuseIdentifier: HomeFooterCell.className)
}
}

// MARK: - UITableViewDataSource
extension HomeVC: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 4
}

// MARK: Cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let tableSection = HomeBackgroundTVSectionType(rawValue: section) {
switch tableSection {
case .banner:
return 1
case .review:
return 2
case .questionPerson:
return 4
case .community:
return 2
}
} else { return 0 }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let tableSection = HomeBackgroundTVSectionType(rawValue: indexPath.section) {
switch tableSection {
case .banner:
return UITableViewCell()
case .review:
return UITableViewCell()
case .questionPerson:
return UITableViewCell()
case .community:
return UITableViewCell()
}
} else { return UITableViewCell() }
}
}

// MARK: - UITableViewDelegate
extension HomeVC: UITableViewDelegate {

// MARK: Header
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if let tableSection = HomeBackgroundTVSectionType(rawValue: section) {
switch tableSection {
case .banner:
guard let headerView = tableView.dequeueReusableCell(withIdentifier: HomeBannerHeaderCell.className) as? HomeBannerHeaderCell else { return HomeBannerHeaderCell() }
return headerView
case .review:
guard let headerView = tableView.dequeueReusableCell(withIdentifier: HomeTitleHeaderCell.className) as? HomeTitleHeaderCell else { return HomeTitleHeaderCell() }
headerView.setTitleLabel(titleText: "후기")
return headerView
case .questionPerson:
guard let headerView = tableView.dequeueReusableCell(withIdentifier: HomeTitleHeaderCell.className) as? HomeTitleHeaderCell else { return HomeTitleHeaderCell() }
headerView.setTitleLabel(titleText: "1:1질문")
return headerView
case .community:
guard let headerView = tableView.dequeueReusableCell(withIdentifier: HomeTitleHeaderCell.className) as? HomeTitleHeaderCell else { return HomeTitleHeaderCell() }
headerView.setTitleLabel(titleText: "커뮤니티")
return headerView
}
} else { return UIView() }
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if let tableSection = HomeBackgroundTVSectionType(rawValue: section) {
switch tableSection {
case .banner:
let headerHeight = 60.0
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: headerHeight))
tableView.contentInset = UIEdgeInsets(top: -headerHeight, left: 0, bottom: 0, right: 0)
return headerHeight
case .review, .questionPerson, .community:
return 70
}
} else { return 0 }
}

// MARK: Footer
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if let tableSection = HomeBackgroundTVSectionType(rawValue: section) {
switch tableSection {
case .review, .questionPerson:
guard let footerView = tableView.dequeueReusableCell(withIdentifier: HomeFooterCell.className) as? HomeFooterCell else { return HomeFooterCell() }
return footerView
default:
return nil
}
} else { return nil }
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if let tableSection = HomeBackgroundTVSectionType(rawValue: section) {
switch tableSection {
case .review, .questionPerson:
return 12
default:
return 0
}
} else { return 0 }
}
}

// MARK: - UI
extension HomeVC {
private func configureUI() {
navigationController?.navigationBar.isHidden = true
view.backgroundColor = .white
view.addSubviews([tabLabel])
view.addSubviews([backgroundTV])

tabLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
backgroundTV.snp.makeConstraints {
$0.horizontalEdges.verticalEdges.equalTo(view.safeAreaLayoutGuide)
}
}
}
Loading

0 comments on commit 2e1778f

Please sign in to comment.