Skip to content

Commit 179fb17

Browse files
committed
Feat: UIViewController extension에 공통 backbutton을 사용할 수 있도록 커스텀
1 parent d61d940 commit 179fb17

7 files changed

Lines changed: 78 additions & 26 deletions

File tree

Projects/App/Resources/LaunchScreen.storyboard

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,38 @@
1616
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
1717
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1818
<subviews>
19-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright © 2025 com.bitnagil. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
20-
<rect key="frame" x="0.0" y="811.66666666666663" width="393" height="20.333333333333371"/>
21-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
22-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23-
<nil key="highlightedColor"/>
24-
</label>
25-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Bitnagil" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
26-
<rect key="frame" x="0.0" y="263.66666666666669" width="393" height="43"/>
27-
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
28-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
29-
<nil key="highlightedColor"/>
30-
</label>
19+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PLm-O2-pYg">
20+
<rect key="frame" x="20" y="259" width="353" height="334"/>
21+
<subviews>
22+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Bitnagil" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dEo-10-Cez">
23+
<rect key="frame" x="123" y="149" width="107" height="36"/>
24+
<fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
25+
<nil key="textColor"/>
26+
<nil key="highlightedColor"/>
27+
</label>
28+
</subviews>
29+
<color key="backgroundColor" red="0.76078431372549016" green="0.76862745098039209" blue="0.78431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
30+
<constraints>
31+
<constraint firstItem="dEo-10-Cez" firstAttribute="centerX" secondItem="PLm-O2-pYg" secondAttribute="centerX" id="Tfr-eg-2qd"/>
32+
<constraint firstItem="dEo-10-Cez" firstAttribute="centerY" secondItem="PLm-O2-pYg" secondAttribute="centerY" id="dWo-st-RGp"/>
33+
</constraints>
34+
</view>
3135
</subviews>
3236
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
3337
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3438
<constraints>
35-
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
36-
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
37-
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
38-
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
39-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
40-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
39+
<constraint firstItem="PLm-O2-pYg" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="9cn-j0-5Zm"/>
40+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="trailing" secondItem="PLm-O2-pYg" secondAttribute="trailing" constant="20" id="Buq-td-Lm2"/>
41+
<constraint firstItem="PLm-O2-pYg" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" id="E9P-56-2M2"/>
42+
<constraint firstItem="PLm-O2-pYg" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="SbZ-Sq-Opn"/>
43+
<constraint firstItem="PLm-O2-pYg" firstAttribute="top" secondItem="Bcu-3y-fUS" secondAttribute="top" constant="200" id="dic-7N-u8I"/>
44+
<constraint firstItem="PLm-O2-pYg" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="hlQ-mO-iXo"/>
4145
</constraints>
4246
</view>
4347
</viewController>
4448
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
4549
</objects>
46-
<point key="canvasLocation" x="53" y="375"/>
50+
<point key="canvasLocation" x="52.671755725190835" y="374.64788732394368"/>
4751
</scene>
4852
</scenes>
4953
</document>

Projects/App/Sources/SceneDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2121

2222
let introView = IntroView()
2323
let navigationController = UINavigationController(rootViewController: introView)
24-
navigationController.isNavigationBarHidden = true
24+
2525
window.rootViewController = navigationController
2626
window.makeKeyAndVisible()
2727

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// UIViewController+.swift
3+
// Presentation
4+
//
5+
// Created by 최정인 on 7/8/25.
6+
//
7+
8+
import UIKit
9+
10+
extension UIViewController {
11+
12+
func configureNavigationBar(navigationStyle: NavigationBarStyle) {
13+
switch navigationStyle {
14+
case .hidden:
15+
navigationController?.setNavigationBarHidden(true, animated: false)
16+
case .withBackButton(let title):
17+
navigationController?.setNavigationBarHidden(false, animated: false)
18+
self.title = title
19+
configureDefaultBackButton()
20+
}
21+
}
22+
23+
func configureDefaultBackButton() {
24+
let backButton = UIBarButtonItem(
25+
image: UIImage(systemName: "chevron.left"),
26+
style: .plain,
27+
target: self,
28+
action: #selector(popViewController))
29+
backButton.tintColor = .black
30+
navigationItem.leftBarButtonItem = backButton
31+
}
32+
33+
@objc private func popViewController() {
34+
navigationController?.popViewController(animated: true)
35+
}
36+
}
37+
38+
enum NavigationBarStyle {
39+
case hidden
40+
case withBackButton(title: String)
41+
}

Projects/Presentation/Sources/Login/View/IntroView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public final class IntroView: UIViewController {
3131
configureLayout()
3232
}
3333

34+
public override func viewWillAppear(_ animated: Bool) {
35+
super.viewWillAppear(animated)
36+
configureNavigationBar(navigationStyle: .hidden)
37+
}
38+
3439
private func configureAttribute() {
3540
introLabel.do {
3641
let text = "당신의 하루 리듬을 이해하고,\n작은 변화를 함께 시작해볼게요."

Projects/Presentation/Sources/Login/View/LoginView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public final class LoginView: BaseViewController<LoginViewModel> {
4141
super.viewDidLoad()
4242
}
4343

44+
public override func viewWillAppear(_ animated: Bool) {
45+
super.viewWillAppear(animated)
46+
configureNavigationBar(navigationStyle: .hidden)
47+
}
48+
4449
override func configureAttribute() {
4550
logoView.do {
4651
$0.backgroundColor = BitnagilColor.gray90

Projects/Presentation/Sources/Login/View/TermsAgreementView.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import UIKit
99
import Combine
10+
import Domain
1011
import Shared
1112
import SnapKit
1213
import Then
@@ -46,15 +47,10 @@ public final class TermsAgreementView: BaseViewController<LoginViewModel> {
4647

4748
public override func viewWillAppear(_ animated: Bool) {
4849
super.viewWillAppear(animated)
49-
navigationController?.setNavigationBarHidden(false, animated: true)
50+
configureNavigationBar(navigationStyle: .withBackButton(title: "약관 동의"))
5051
}
5152

5253
override func configureAttribute() {
53-
title = "약관 동의"
54-
let backBarButtonItem = UIBarButtonItem(title: nil, style: .plain, target: self, action: nil)
55-
backBarButtonItem.tintColor = .black
56-
self.navigationItem.backBarButtonItem = backBarButtonItem
57-
5854
agreementLabel.do {
5955
let text = "빛나길 이용을 위해\n필수 약관에 동의해 주세요."
6056
$0.attributedText = BitnagilFont(style: .title2, weight: .bold).attributedString(text: text)

Projects/Presentation/Sources/Login/ViewModel/LoginViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public final class LoginViewModel: ViewModel {
8181
try await loginUseCase.sumbitAgreement(agreements: agreements)
8282
agreementResultSubject.send(true)
8383
} catch {
84+
BitnagilLogger.log(logType: .error, message: "\(error.localizedDescription)")
8485
agreementResultSubject.send(false)
8586
}
8687
}

0 commit comments

Comments
 (0)