Skip to content

Commit

Permalink
[Chore] CDS-Mobile1#27 - 뼈대뷰 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
joonBaek12 committed Jun 2, 2023
1 parent a726470 commit d81272f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class DMCollectionViewCell: BaseCollectionViewCell {
userProfileView.snp.makeConstraints {
$0.top.equalToSuperview().offset(10)
$0.leading.equalToSuperview().offset(7)
$0.width.height.equalTo(58)
$0.centerX.equalToSuperview()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ import UIKit

import SnapKit

final class DMTableViewHeader: UITableViewHeaderFooterView {
final class DMTableViewHeader: UIView {

static let identifier = "DMTableViewHeader"
private lazy var storyCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal

let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.showsVerticalScrollIndicator = false
return collectionView
}()

private let titleLabel: UILabel = {
let label = UILabel()
Expand All @@ -30,9 +38,11 @@ final class DMTableViewHeader: UITableViewHeaderFooterView {
return textField
}()

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: DMTableViewHeader.identifier)
override init(frame: CGRect) {
super.init(frame: frame)

register()
configDelegate()
setLayout()
setSearchTextFieldUI()
}
Expand All @@ -41,20 +51,42 @@ final class DMTableViewHeader: UITableViewHeaderFooterView {
fatalError("init(coder:) has not been implemented")
}

//MARK: - Setting

private func register() {
storyCollectionView.register(DMCollectionViewCell.self, forCellWithReuseIdentifier: DMCollectionViewCell.identifier)
}

private func configDelegate() {
storyCollectionView.delegate = self
storyCollectionView.dataSource = self
}

private func setLayout() {

contentView.addSubview(searchTextField)
backgroundColor = .white1

addSubview(searchTextField)
searchTextField.snp.makeConstraints {
$0.top.centerX.equalToSuperview()
$0.top.centerX.equalToSuperview().offset(8)
$0.centerX.equalToSuperview()
$0.leading.equalToSuperview().offset(16)
$0.height.equalTo(35)
}

contentView.addSubview(titleLabel)
addSubview(titleLabel)
titleLabel.snp.makeConstraints {
$0.top.equalTo(searchTextField.snp.bottom).offset(18)
$0.leading.equalToSuperview().offset(20)
}

addSubview(storyCollectionView)
storyCollectionView.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom).offset(4)
$0.centerX.equalToSuperview()
$0.leading.equalToSuperview().offset(14)
$0.height.equalTo(90)
}
}

private func setSearchTextFieldUI() {
Expand All @@ -67,3 +99,38 @@ final class DMTableViewHeader: UITableViewHeaderFooterView {
}
}

//MARK: - UICollectionViewDelegateFlowLayout

extension DMTableViewHeader: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 72, height: 90)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 4
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}

// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
// return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
// }
}

//MARK: - UICollectionViewDataSource

extension DMTableViewHeader: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 9
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DMCollectionViewCell.identifier, for: indexPath) as? DMCollectionViewCell else { return UICollectionViewCell() }

return cell
}


}
121 changes: 27 additions & 94 deletions Instagram-iOS/Instagram-iOS/Screens/DMList/DMList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@
//

import UIKit

import SnapKit

final class DMListViewController: BaseViewController {

// MARK: - Property

// MARK: - UI Property

let header = UIView()

private let headerTitleLabel: UILabel = {
let label = UILabel()
label.font = .bodyKorBold
label.textColor = .black1
label.text = "즐겨찾기"
return label
}()

private let searchTextField: UITextField = {
let textField = UITextField()
textField.backgroundColor = .gray5
textField.font = .body
//TODO: - 추후 placeholder 세팅 시 추가하겠습니다
// textField.placeholder = "검색"
return textField
}()
private let headerView = DMTableViewHeader()

let userNameLabel: UILabel = {
let label = UILabel()
Expand All @@ -56,17 +36,9 @@ final class DMListViewController: BaseViewController {

let customNaviView = UIView()

// private let searchTextField: UITextField = {
// let textField = UITextField()
// textField.backgroundColor = .gray5
// textField.font = .body
// //TODO: - 추후 placeholder 세팅 시 추가하겠습니다
//// textField.placeholder = "검색"
// return textField
// }()

private let DMListTableView: UITableView = {
let tableView = UITableView()
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.separatorColor = .clear
tableView.register(DMTableViewCellHeader.self, forHeaderFooterViewReuseIdentifier: DMTableViewCellHeader.identifier)
tableView.register(DMTableviewCell.self, forCellReuseIdentifier: DMTableviewCell.identifier)
return tableView
Expand All @@ -78,14 +50,10 @@ final class DMListViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

// setSearchTextFieldUI()
configDelegate()
setSearchTextFieldUI()
configTableView()
}

// MARK: - Setting

private func configDelegate() {
private func configTableView() {
DMListTableView.delegate = self
DMListTableView.dataSource = self
}
Expand All @@ -111,81 +79,48 @@ final class DMListViewController: BaseViewController {
}

override func setLayout() {

DMListTableView.tableHeaderView = header

view.addSubview(header)
header.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.leading.trailing.equalToSuperview()
$0.height.equalTo(155)
}

header.addSubview(searchTextField)
searchTextField.snp.makeConstraints {
$0.top.centerX.equalToSuperview()
$0.leading.equalToSuperview().offset(16)
$0.height.equalTo(35)
}

view.addSubview(customNaviView)
customNaviView.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide.snp.top)
$0.leading.trailing.equalToSuperview()
}

// view.addSubview(searchTextField)
// searchTextField.snp.makeConstraints {
// $0.top.equalTo(customNaviView.snp.bottom).offset(8)
// $0.centerX.equalToSuperview()
// $0.leading.equalToSuperview().offset(16)
// $0.height.equalTo(35)
// }

DMListTableView.tableHeaderView = headerView

view.addSubview(DMListTableView)
DMListTableView.snp.makeConstraints {
$0.edges.equalToSuperview()
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.leading.bottom.trailing.equalToSuperview()
}
}

private func setSearchTextFieldUI() {

searchTextField.layer.cornerRadius = 10
searchTextField.backgroundColor = .gray5
searchTextField.font = .body
// searchTextField.attributedPlaceholder = NSAttributedString(string: "검색", attributes: [NSAttributedString.Key.foregroundColor: UIColor.lightGray])

}
}

//MARK: - UITableViewDelegate

extension DMListViewController: UITableViewDelegate {}

//MARK: - UITableViewDataSource

extension DMListViewController: UITableViewDataSource {

//MARK: - Header

// func numberOfSections(in tableView: UITableView) -> Int {
// return 1 // set your desired number of sections
// }

extension DMListViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: DMTableViewCellHeader.identifier) as? DMTableViewCellHeader else {
fatalError("header fail")
switch section {
case 0:
return DMTableViewHeader()
default:
guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: DMTableViewCellHeader.identifier) as? DMTableViewCellHeader else {fatalError("header fail")}
return header
}

return header
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 47
switch section {
case 0:
return 172
default:
return 47
}
}

//MARK: - Cells

}

//MARK: - UITableViewDataSource

extension DMListViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
Expand All @@ -198,6 +133,4 @@ extension DMListViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 74
}


}

0 comments on commit d81272f

Please sign in to comment.