22// Toast.swift
33// Runnect-iOS
44//
5- // Created by sejin on 2022/12/31 .
5+ // Created by 이명진 on 2024/03/25 .
66//
77
88import UIKit
99
1010import SnapKit
11+ import Then
1112
1213public 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
2228public 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
0 commit comments