Skip to content

Commit

Permalink
[Feat] #244 - custom navigation view 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongdung-eo committed Mar 21, 2024
1 parent 3269752 commit ad50ab6
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// NOTTODONavigationView.swift
// iOS-NOTTODO
//
// Created by JEONGEUN KIM on 3/20/24.
//

import UIKit

import SnapKit
import Then

protocol NavigationDelegate: AnyObject {
func popViewController()
}

final class NottodoNavigationView: UIView {

// MARK: - Property

weak var delegate: NavigationDelegate?

// MARK: - UI Components

private let backButton = UIButton()
private let navigationTitle = UILabel()
private let seperateView = UIView()

override init(frame: CGRect) {
super.init(frame: .zero)

setUI()
setLayout()
}

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

extension NottodoNavigationView {

private func setUI() {

seperateView.do {
$0.backgroundColor = .gray2
}
backButton.do {
$0.setBackgroundImage(.icBack, for: .normal)
$0.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside)
}

navigationTitle.do {
$0.font = .Pretendard(.semiBold, size: 18)
$0.textColor = .white
}
}

private func setLayout() {
self.addSubviews(backButton, navigationTitle, seperateView)

self.snp.makeConstraints {
$0.height.equalTo(58)
}

backButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(15)
}

navigationTitle.snp.makeConstraints {
$0.center.equalToSuperview()
}

seperateView.snp.makeConstraints {
$0.bottom.horizontalEdges.equalToSuperview()
$0.height.equalTo(0.7)
}
}

func setTitle(_ text: String) {
navigationTitle.text = text
}

@objc
private func backButtonTapped() {
delegate?.popViewController()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class RecommendActionViewController: UIViewController {

// MARK: - UI Components

private let navigationView = UIView()
private let backButton = UIButton()
private let navigationTitle = UILabel()
private let navigationView = NottodoNavigationView()
private let nextButton = UIButton()
private var isTapped: Bool = false {
didSet {
Expand Down Expand Up @@ -111,15 +109,9 @@ private extension RecommendActionViewController {
// $0.allowsMultipleSelection = true 생성뷰 이슈 해결 후 주석 해제
}

backButton.do {
$0.setBackgroundImage(.back, for: .normal)
$0.addTarget(self, action: #selector(backButtonDidTapped), for: .touchUpInside)
}

navigationTitle.do {
$0.font = .Pretendard(.semiBold, size: 18)
$0.textColor = .white
$0.text = I18N.recommendNavTitle
navigationView.do {
$0.delegate = self
$0.setTitle(I18N.recommendNavTitle)
}

nextButton.do {
Expand All @@ -135,23 +127,12 @@ private extension RecommendActionViewController {

func setLayout() {
view.addSubviews(navigationView, recommendActionCollectionView, nextButton)
navigationView.addSubviews(backButton, navigationTitle)

navigationView.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.directionalHorizontalEdges.equalToSuperview()
$0.height.equalTo(58)
}

backButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().offset(15)
}

navigationTitle.snp.makeConstraints {
$0.center.equalToSuperview()
}


recommendActionCollectionView.snp.makeConstraints {
$0.top.equalTo(navigationView.snp.bottom)
$0.leading.trailing.equalToSuperview()
Expand Down Expand Up @@ -186,11 +167,6 @@ private extension RecommendActionViewController {
recommendActionCollectionView.delegate = self
recommendActionCollectionView.dataSource = self
}

@objc
func backButtonDidTapped() {
coordinator?.popViewController()
}
}

extension RecommendActionViewController: UICollectionViewDelegateFlowLayout {
Expand Down Expand Up @@ -299,3 +275,9 @@ extension RecommendActionViewController {
}
}
}

extension RecommendActionViewController: NavigationDelegate {
func popViewController() {
coordinator?.popViewController()
}
}

0 comments on commit ad50ab6

Please sign in to comment.