Skip to content

Commit

Permalink
[Feat] - CDS-Mobile1#27 TabelViewHeader 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
joonBaek12 committed May 26, 2023
1 parent cafdb19 commit 63bed21
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Instagram-iOS/Instagram-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
372AAF732A20E7FC009212A8 /* DMTableviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372AAF722A20E7FC009212A8 /* DMTableviewCell.swift */; };
372AAF752A20E808009212A8 /* DMCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372AAF742A20E808009212A8 /* DMCollectionViewCell.swift */; };
372AAF772A20F90F009212A8 /* DMTableViewHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372AAF762A20F90F009212A8 /* DMTableViewHeader.swift */; };
37C4BF062A1D3E86006FBFF6 /* SF-Pro-Text-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 37C4BF052A1D3E86006FBFF6 /* SF-Pro-Text-Bold.ttf */; };
3E6CF47A2A14F43500DC3B2B /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6CF4792A14F43500DC3B2B /* BaseViewController.swift */; };
3E6CF47C2A14F63700DC3B2B /* BaseTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6CF47B2A14F63700DC3B2B /* BaseTableViewCell.swift */; };
Expand Down Expand Up @@ -55,6 +56,7 @@
/* Begin PBXFileReference section */
372AAF722A20E7FC009212A8 /* DMTableviewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMTableviewCell.swift; sourceTree = "<group>"; };
372AAF742A20E808009212A8 /* DMCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMCollectionViewCell.swift; sourceTree = "<group>"; };
372AAF762A20F90F009212A8 /* DMTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMTableViewHeader.swift; sourceTree = "<group>"; };
37C4BF052A1D3E86006FBFF6 /* SF-Pro-Text-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-Pro-Text-Bold.ttf"; sourceTree = "<group>"; };
37D49A6D2A17CE5C00FBCA0F /* UIStackView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+.swift"; sourceTree = "<group>"; };
37D49A6F2A18891600FBCA0F /* UITextfield+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextfield+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,6 +120,7 @@
children = (
372AAF722A20E7FC009212A8 /* DMTableviewCell.swift */,
372AAF742A20E808009212A8 /* DMCollectionViewCell.swift */,
372AAF762A20F90F009212A8 /* DMTableViewHeader.swift */,
);
path = Cell;
sourceTree = "<group>";
Expand Down Expand Up @@ -457,6 +460,7 @@
7E0148C02A1BEA9A0036147D /* StoryCollectionViewCell.swift in Sources */,
3E9683E62A16392900D6DD30 /* ImageLiteral.swift in Sources */,
3EEE76682A176C9100D0B80E /* NewPostImageCollectionViewCell.swift in Sources */,
372AAF772A20F90F009212A8 /* DMTableViewHeader.swift in Sources */,
7E8DF5A02A1238840023948F /* Models.swift in Sources */,
7E0148BE2A1BE8780036147D /* StoryCollectionView.swift in Sources */,
3E6CF47E2A14F84500DC3B2B /* BaseCollectionViewCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// DMTableViewHeader.swift
// Instagram-iOS
//
// Created by Joon Baek on 2023/05/26.
//

import UIKit

import SnapKit

final class DMTableViewHeader: UITableViewHeaderFooterView {

static let identifier = "DMTableViewHeader"

private let titleLabel: 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
}()

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

setLayout()
setSearchTextFieldUI()
}

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

private func setLayout() {

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

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

private func setSearchTextFieldUI() {

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

}
}

56 changes: 19 additions & 37 deletions Instagram-iOS/Instagram-iOS/Screens/DMList/DMList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ 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()
tableView.register(DMTableviewCell.self, forCellReuseIdentifier: DMTableviewCell.identifier)
tableView.register(DMTableViewHeader.self, forHeaderFooterViewReuseIdentifier: DMTableViewHeader.identifier)
return tableView
}()

Expand All @@ -57,11 +49,10 @@ final class DMListViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

// setSearchTextFieldUI()
configDelegate()
}
}

// MARK: - Setting
// MARK: - Setting

private func configDelegate() {
DMListTableView.delegate = self
Expand Down Expand Up @@ -96,43 +87,35 @@ final class DMListViewController: BaseViewController {
$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)
// }

view.addSubview(DMListTableView)
DMListTableView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
}

// MARK: - Action Helper

// MARK: - Custom Method

// 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 {

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 82 + 90 + 22
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: DMTableViewHeader.identifier) as! DMTableViewHeader
return headerView
}
}

//MARK: - UITableViewDataSource
extension DMListViewController: UITableViewDataSource {

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
return 10 // set your desired number of rows per section
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand All @@ -141,8 +124,7 @@ extension DMListViewController: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 74
return 74 // set your desired row height
}


}

0 comments on commit 63bed21

Please sign in to comment.