-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUIViewController+.swift
More file actions
97 lines (82 loc) · 3.44 KB
/
UIViewController+.swift
File metadata and controls
97 lines (82 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// UIViewController+.swift
// Presentation
//
// Created by 최정인 on 7/8/25.
//
import UIKit
extension UIViewController {
// MARK: - NavigationBar
func configureNavigationBar(navigationStyle: NavigationBarStyle) {
let appearance = UINavigationBarAppearance()
appearance.backgroundEffect = .none
appearance.configureWithOpaqueBackground()
appearance.shadowColor = .clear
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
switch navigationStyle {
case .hidden:
navigationController?.setNavigationBarHidden(true, animated: false)
case .withBackButton(let title):
navigationController?.setNavigationBarHidden(false, animated: false)
self.title = title
configureDefaultBackButton()
case .withPrograssBar(let step, let stepCount):
navigationController?.setNavigationBarHidden(false, animated: false)
configureDefaultBackButton()
configureProgressNavigationBar(step: step, stepCount: stepCount)
case .withPrograssBarWithCustomBackButton(let step, let stepCount):
navigationController?.setNavigationBarHidden(false, animated: false)
configureCustomBackButton()
configureProgressNavigationBar(step: step, stepCount: stepCount)
}
}
private func configureDefaultBackButton() {
let backButton = UIBarButtonItem(
image: UIImage(systemName: "chevron.left"),
style: .plain,
target: self,
action: #selector(popViewController))
backButton.tintColor = .black
navigationItem.leftBarButtonItem = backButton
}
private func configureCustomBackButton() {
let backButton = UIBarButtonItem(
image: UIImage(systemName: "chevron.left"),
style: .plain,
target: self,
action: #selector(popTwoViewControllers))
backButton.tintColor = .black
navigationItem.leftBarButtonItem = backButton
}
private func configureProgressNavigationBar(step: Int, stepCount: Int) {
self.title = ""
let progressView = ProgressBarView(step: step, stepCount: stepCount)
navigationItem.titleView = progressView
}
@objc private func popViewController() {
navigationController?.popViewController(animated: true)
}
@objc private func popTwoViewControllers() {
guard let navigationController = navigationController
else { return }
let viewControllers = navigationController.viewControllers
guard viewControllers.count >= 3 else {
navigationController.popViewController(animated: true)
return
}
let targetViewController = viewControllers[viewControllers.count - 3]
navigationController.popToViewController(targetViewController, animated: true)
}
// MARK: - BottomSheet
func presentCustomBottomSheet(contentViewController: UIViewController, maxHeight: CGFloat) {
let bottomSheet = CustomBottomSheet(contentViewController: contentViewController, maxHeight: maxHeight)
present(bottomSheet, animated: true)
}
}
enum NavigationBarStyle {
case hidden
case withBackButton(title: String)
case withPrograssBar(step: Int, stepCount: Int)
case withPrograssBarWithCustomBackButton(step: Int, stepCount: Int)
}