Skip to content

Commit b7f0d3e

Browse files
committed
[Feat] #265 - Toast 메세지 Height 기능 추가
키보드로 인하여 "Toast 메시지"가 안 보일 수 있기 때문에 조정하는 파라미터와 로직을 추가했습니다.
1 parent 59a7da7 commit b7f0d3e

3 files changed

Lines changed: 36 additions & 27 deletions

File tree

Runnect-iOS/Runnect-iOS/Global/Utils/Toast.swift

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
// Toast.swift
33
// Runnect-iOS
44
//
5-
// Created by sejin on 2022/12/31.
5+
// Created by 이명진 on 2024/03/25.
66
//
77

88
import UIKit
99

1010
import SnapKit
11+
import Then
1112

1213
public extension UIViewController {
13-
func showToast(message: String) {
14-
Toast.show(message: message, view: self.view, safeAreaBottomInset: self.safeAreaBottomInset())
14+
func showToast(message: String, heightOffset: CGFloat = 0) {
15+
Toast.show(
16+
message: message,
17+
view: self.view,
18+
safeAreaBottomInset: self.safeAreaBottomInset(),
19+
heightOffset: heightOffset
20+
)
1521
}
1622

1723
func showNetworkFailureToast() {
@@ -20,34 +26,39 @@ public extension UIViewController {
2026
}
2127

2228
public class Toast {
23-
public static func show(message: String, view: UIView, safeAreaBottomInset: CGFloat = 0) {
24-
25-
let toastContainer = UIView()
26-
let toastLabel = UILabel()
27-
28-
toastContainer.backgroundColor = UIColor.g2.withAlphaComponent(0.7)
29-
toastContainer.alpha = 1.0
30-
toastContainer.layer.cornerRadius = 15
31-
toastContainer.clipsToBounds = true
32-
toastContainer.isUserInteractionEnabled = false
29+
public static func show(
30+
message: String,
31+
view: UIView,
32+
safeAreaBottomInset: CGFloat = 0,
33+
heightOffset: CGFloat = 0
34+
) {
35+
let toastContainer = UIView().then {
36+
$0.backgroundColor = UIColor.g2.withAlphaComponent(0.7)
37+
$0.alpha = 1.0
38+
$0.layer.cornerRadius = 15
39+
$0.clipsToBounds = true
40+
$0.isUserInteractionEnabled = false
41+
}
3342

34-
toastLabel.textColor = .m4
35-
toastLabel.font = .b4
36-
toastLabel.textAlignment = .center
37-
toastLabel.text = message
38-
toastLabel.clipsToBounds = true
39-
toastLabel.numberOfLines = 0
40-
toastLabel.sizeToFit()
43+
let toastLabel = UILabel().then {
44+
$0.textColor = .m4
45+
$0.font = .b4
46+
$0.textAlignment = .center
47+
$0.text = message
48+
$0.clipsToBounds = true
49+
$0.numberOfLines = 0
50+
$0.sizeToFit()
51+
}
4152

4253
toastContainer.addSubview(toastLabel)
4354
view.addSubview(toastContainer)
4455

45-
let toastConatinerWidth = toastLabel.intrinsicContentSize.width + 40.0
56+
let toastContainerWidth = toastLabel.intrinsicContentSize.width + 40.0
4657

4758
toastContainer.snp.makeConstraints {
4859
$0.centerX.equalToSuperview()
49-
$0.bottom.equalToSuperview().inset(safeAreaBottomInset+160)
50-
$0.width.equalTo(toastConatinerWidth)
60+
$0.bottom.equalToSuperview().inset(safeAreaBottomInset + 160 + heightOffset)
61+
$0.width.equalTo(toastContainerWidth)
5162
$0.height.equalTo(31)
5263
}
5364

Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/NicknameEditorVC.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ extension NicknameEditorVC {
183183

184184
guard nickname != self.currentNickname else {
185185
print("💪 닉네임 변경 시도 전에 현재 닉네임과 동일한지 검사 성공 처리")
186-
// self.delegate?.nicknameEditDidSuccess()
187-
// 닉네임 같은데 굳이 또 서버 요청을 할 필요가 있나?
188186
self.navigationController?.popViewController(animated: false)
189187
return
190188
}
@@ -203,7 +201,7 @@ extension NicknameEditorVC {
203201
self.showNetworkFailureToast()
204202
}
205203
case .failure(let error):
206-
self.showToast(message: "중복된 닉네임입니다.")
204+
self.showToast(message: "중복된 닉네임입니다.", heightOffset: 100)
207205
print(error.localizedDescription)
208206
}
209207
}

Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/NickNameSetUpVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extension NickNameSetUpVC {
174174
}
175175
case .failure(let error):
176176
print(error.localizedDescription)
177-
self.showNetworkFailureToast()
177+
self.showToast(message: "중복된 닉네임입니다.", heightOffset: 100)
178178
}
179179
}
180180
}

0 commit comments

Comments
 (0)