55// Created by 최정인 on 7/8/25.
66//
77
8+ import SnapKit
89import UIKit
910
1011extension UIViewController {
1112 // MARK: - NavigationBar
12- func configureNavigationBar( navigationStyle: NavigationBarStyle ) {
13- switch navigationStyle {
14- case . hidden:
15- navigationController? . setNavigationBarHidden ( true , animated: false )
13+ enum NavigationBarStyle {
14+ case withBackButton( title: String ) // 백버튼 + 타이틀 (없으면 빈 String)
15+ case withTitle( title: String ) // 오로지 타이틀만
16+ case withProgressBar( step: Int ) // 백버튼 + progress
17+ }
1618
17- case . withBackButton( let title) :
18- navigationController? . setNavigationBarHidden ( false , animated: false )
19- self . title = title
20- configureDefaultBackButton ( )
21-
22- case . withPrograssBar( let step, let stepCount) :
23- navigationController? . setNavigationBarHidden ( false , animated: false )
24- configureDefaultBackButton ( )
25- configureProgressNavigationBar ( step: step, stepCount: stepCount)
26-
27- case . withPrograssBarWithCustomBackButton( let step, let stepCount) :
28- navigationController? . setNavigationBarHidden ( false , animated: false )
29- configureCustomBackButton ( )
30- configureProgressNavigationBar ( step: step, stepCount: stepCount)
31-
32- case . withPrograssBarWithoutBackButton( let step, let stepCount) :
33- navigationController? . setNavigationBarHidden ( false , animated: false )
34- navigationItem. setHidesBackButton ( true , animated: false )
35- configureProgressNavigationBar ( step: step, stepCount: stepCount)
19+ func configureCustomNaviagtionBar( navigationBarStyle: NavigationBarStyle ) {
20+ let safeArea = self . view. safeAreaLayoutGuide
21+ let navigationBar : UIView = customNavigationBar ( navigationBarStyle: navigationBarStyle)
22+
23+ self . view. addSubview ( navigationBar)
24+ navigationBar. snp. makeConstraints { make in
25+ make. top. horizontalEdges. equalTo ( safeArea)
26+ make. height. equalTo ( 48 )
3627 }
3728 }
3829
39- private func configureDefaultBackButton( ) {
40- let backButton = UIBarButtonItem (
41- image: UIImage ( systemName: " chevron.left " ) ,
42- style: . plain,
43- target: self ,
44- action: #selector( popViewController) )
45- backButton. tintColor = . black
46- navigationItem. leftBarButtonItem = backButton
47- changeNavigationBackground ( color: . white)
48- }
30+ private func customNavigationBar( navigationBarStyle: NavigationBarStyle ) -> UIView {
31+ let navigationBar = UIView ( )
32+ let customBackButton = UIButton ( )
33+ let titleLabel = UILabel ( )
34+ let progressView = UIImageView ( )
4935
50- private func configureCustomBackButton( ) {
51- let backButton = UIBarButtonItem (
52- image: UIImage ( systemName: " chevron.left " ) ,
53- style: . plain,
54- target: self ,
55- action: #selector( popTwoViewControllers) )
56- backButton. tintColor = . black
57- navigationItem. leftBarButtonItem = backButton
58- changeNavigationBackground ( color: . white)
59- }
36+ customBackButton. setImage ( BitnagilIcon . backButtonIcon, for: . normal)
37+ customBackButton. addAction (
38+ UIAction { [ weak self] _ in
39+ self ? . navigationController? . popViewController ( animated: true )
40+ } ,
41+ for: . touchUpInside)
6042
61- private func configureProgressNavigationBar( step: Int , stepCount: Int ) {
62- self . title = " "
63- let progressView = ProgressBarView ( step: step, stepCount: stepCount)
64- navigationItem. titleView = progressView
65- changeNavigationBackground ( color: BitnagilColor . gray99)
66- }
43+ titleLabel. text = " "
44+ titleLabel. font = BitnagilFont ( style: . title3, weight: . semiBold) . font
45+ titleLabel. textColor = BitnagilColor . gray10
6746
68- @objc private func popViewController( ) {
69- navigationController? . popViewController ( animated: true )
70- }
47+ progressView. isHidden = true
48+
49+ switch navigationBarStyle {
50+ case . withBackButton( let title) :
51+ titleLabel. text = title
7152
72- @objc private func popTwoViewControllers( ) {
73- guard let navigationController = navigationController
74- else { return }
75- let viewControllers = navigationController. viewControllers
53+ case . withTitle( let title) :
54+ titleLabel. text = title
55+ customBackButton. isHidden = true
7656
77- guard viewControllers. count >= 3 else {
78- navigationController. popViewController ( animated: true )
79- return
57+ case . withProgressBar( let step) :
58+ titleLabel. isHidden = true
59+ progressView. image = progressImage ( step: step)
60+ progressView. isHidden = false
8061 }
8162
82- let targetViewController = viewControllers [ viewControllers. count - 3 ]
83- navigationController. popToViewController ( targetViewController, animated: true )
84- }
63+ navigationBar. backgroundColor = . systemBackground
64+ [ customBackButton, titleLabel, progressView] . forEach {
65+ navigationBar. addSubview ( $0)
66+ }
8567
86- private func changeNavigationBackground( color: UIColor ? ) {
87- let appearance = UINavigationBarAppearance ( )
88- appearance. configureWithOpaqueBackground ( )
89- appearance. backgroundColor = color
90- appearance. shadowColor = . clear
68+ customBackButton. snp. makeConstraints { make in
69+ make. top. equalToSuperview ( )
70+ make. leading. equalToSuperview ( )
71+ make. size. equalTo ( 48 )
72+ }
73+
74+ titleLabel. snp. makeConstraints { make in
75+ make. center. equalToSuperview ( )
76+ }
77+
78+ progressView. snp. makeConstraints { make in
79+ make. center. equalToSuperview ( )
80+ }
9181
92- navigationController? . navigationBar. standardAppearance = appearance
93- navigationController? . navigationBar. scrollEdgeAppearance = appearance
94- navigationController? . navigationBar. compactAppearance = appearance
82+ return navigationBar
83+ }
84+
85+ private func progressImage( step: Int ) -> UIImage ? {
86+ switch step {
87+ case 1 : BitnagilGraphic . progressStep1
88+ case 2 : BitnagilGraphic . progressStep2
89+ case 3 : BitnagilGraphic . progressStep3
90+ case 4 : BitnagilGraphic . progressStep4
91+ case 5 : BitnagilGraphic . progressStep5
92+ default : nil
93+ }
9594 }
9695
9796 // MARK: - BottomSheet
@@ -100,11 +99,3 @@ extension UIViewController {
10099 present ( bottomSheet, animated: true )
101100 }
102101}
103-
104- enum NavigationBarStyle {
105- case hidden
106- case withBackButton( title: String )
107- case withPrograssBar( step: Int , stepCount: Int )
108- case withPrograssBarWithCustomBackButton( step: Int , stepCount: Int )
109- case withPrograssBarWithoutBackButton( step: Int , stepCount: Int )
110- }
0 commit comments