From 6edd2ccc3200a385b7265be024e8bb6d9eb74c7d Mon Sep 17 00:00:00 2001 From: yoonseo Date: Wed, 15 Sep 2021 21:12:02 +0900 Subject: [PATCH] =?UTF-8?q?[#2]=20=EC=97=B0=EB=9D=BD=EC=B2=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20VC=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cells/TextFieldTableViewCell.swift | 65 ++++++++++ .../Sources/Headers/ProfileHeaderView.swift | 48 ++++++++ .../CreateViewController.swift | 111 ++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 CheoMooRac/CheoMooRac/Sources/Cells/TextFieldTableViewCell.swift create mode 100644 CheoMooRac/CheoMooRac/Sources/Headers/ProfileHeaderView.swift create mode 100644 CheoMooRac/CheoMooRac/Sources/ViewControllers/CreateViewController.swift diff --git a/CheoMooRac/CheoMooRac/Sources/Cells/TextFieldTableViewCell.swift b/CheoMooRac/CheoMooRac/Sources/Cells/TextFieldTableViewCell.swift new file mode 100644 index 0000000..fb31fac --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Cells/TextFieldTableViewCell.swift @@ -0,0 +1,65 @@ +// +// TextFieldTableViewCell.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +class TextFieldTableViewCell: UITableViewCell,Reusable { + + private let textField = UITextField().then { + $0.borderStyle = .none + $0.textColor = .systemRed + } + + + private let seperatorView = UIView().then { + $0.backgroundColor = .systemGray5 + } + + public var placeholder: String? { + didSet{ + textField.placeholder = placeholder + } + } + + public var delegate: UITextFieldDelegate? { + didSet{ + textField.delegate = delegate + } + } + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setLayouts() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setLayouts() { + setViewHierarchy() + setConstraints() + } + + private func setViewHierarchy() { + contentView.addSubviews(textField, seperatorView) + } + + private func setConstraints() { + textField.snp.makeConstraints { + $0.leading.trailing.equalToSuperview().inset(20) + $0.top.bottom.equalToSuperview() + } + + seperatorView.snp.makeConstraints { + $0.height.equalTo(1) + $0.leading.equalToSuperview().inset(20) + $0.trailing.equalToSuperview() + $0.bottom.equalToSuperview() + } + } +} diff --git a/CheoMooRac/CheoMooRac/Sources/Headers/ProfileHeaderView.swift b/CheoMooRac/CheoMooRac/Sources/Headers/ProfileHeaderView.swift new file mode 100644 index 0000000..974903b --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/Headers/ProfileHeaderView.swift @@ -0,0 +1,48 @@ +// +// ProfileHeaderView.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +class ProfileHeaderView: UITableViewHeaderFooterView, Reusable { + + private let profileButton = UIButton().then { + $0.setBackgroundColor(.black, for: .normal) + $0.clipsToBounds = true + } + + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + setLayouts() + } + + required init?(coder: NSCoder) { + fatalError("coder doesn't exist") + } + + private func setLayouts() { + setViewHierarchy() + setConstraints() + } + + private func setViewHierarchy() { + contentView.addSubview(profileButton) + } + + private func setConstraints() { + + profileButton.snp.makeConstraints { + $0.width.height.equalTo(100) + $0.centerX.equalToSuperview() + $0.centerY.equalToSuperview() + } + + profileButton.layer.cornerRadius = 50 + + + } + +} diff --git a/CheoMooRac/CheoMooRac/Sources/ViewControllers/CreateViewController.swift b/CheoMooRac/CheoMooRac/Sources/ViewControllers/CreateViewController.swift new file mode 100644 index 0000000..8e99b4b --- /dev/null +++ b/CheoMooRac/CheoMooRac/Sources/ViewControllers/CreateViewController.swift @@ -0,0 +1,111 @@ +// +// CreateViewController.swift +// CheoMooRac +// +// Created by 김윤서 on 2021/09/14. +// + +import UIKit + +class CreateViewController: UIViewController { + + private let tableView = UITableView().then { + $0.sectionHeaderHeight = 140 + $0.rowHeight = 40 + $0.separatorStyle = .none + } + + override func viewDidLoad() { + super.viewDidLoad() + + setNavigationBar() + setTableView() + + setLayouts() + } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default) + navigationController?.navigationBar.shadowImage = UIImage() + navigationController?.navigationBar.backgroundColor = .systemGray5 + } + + private func setTableView() { + tableView.delegate = self + tableView.dataSource = self + + tableView.registerReusableHeaderFooterView(ProfileHeaderView.self) + tableView.registerReusableCell(TextFieldTableViewCell.self) + } + + + private func setNavigationBar() { + title = "새로운 연락처" + + navigationItem.leftBarButtonItem = UIBarButtonItem(title: "취소", style: .plain, target: self, action: #selector(cancelButtonDidTapped)) + navigationItem.rightBarButtonItem = UIBarButtonItem(title: "완료", style: .plain, target: self, action: #selector(completeButtonDidTapped)) + } + + private func setLayouts() { + setViewHierarchy() + setConstraints() + } + + private func setViewHierarchy() { + view.addSubview(tableView) + } + + private func setConstraints() { + tableView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + } +} + +extension CreateViewController { + @objc + func cancelButtonDidTapped(){ + dismiss(animated: true, completion: nil) + } + + @objc + func completeButtonDidTapped(){ + dismiss(animated: true, completion: nil) + } +} + +extension CreateViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + switch section { + case 0: + let header = tableView.dequeueReusableHeaderFooterView() as ProfileHeaderView + return header + default: + return nil + } + } +} + +extension CreateViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 3 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + switch indexPath.section { + case 0: + let cell = tableView.dequeueReusableCell(indexPath: indexPath) as TextFieldTableViewCell + cell.placeholder = "성" + cell.delegate = self + return cell + default: + return UITableViewCell() + } + } + +} + +extension CreateViewController: UITextFieldDelegate { + +}