Skip to content

Commit

Permalink
[#2] 연락처 추가 VC 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
ezidayzi committed Sep 15, 2021
1 parent b67561f commit 6edd2cc
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 0 deletions.
65 changes: 65 additions & 0 deletions CheoMooRac/CheoMooRac/Sources/Cells/TextFieldTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
48 changes: 48 additions & 0 deletions CheoMooRac/CheoMooRac/Sources/Headers/ProfileHeaderView.swift
Original file line number Diff line number Diff line change
@@ -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


}

}
Original file line number Diff line number Diff line change
@@ -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 {

}

0 comments on commit 6edd2cc

Please sign in to comment.