@@ -16,10 +16,8 @@ final class Toast {
16
16
func showToast( message: String ) {
17
17
let scenes : Set < UIScene > = UIApplication . shared. connectedScenes
18
18
let windowScene : UIWindowScene ? = scenes. first as? UIWindowScene
19
- let window : UIWindow ? = windowScene? . windows. first
19
+ guard let window: UIWindow = windowScene? . windows. first else { return }
20
20
let toastLabel : UILabel = UILabel ( )
21
- guard let windowWidth: CGFloat = windowScene? . screen. bounds. width else { return }
22
- guard let windowHeight: CGFloat = windowScene? . screen. bounds. height else { return }
23
21
toastLabel. backgroundColor = . background
24
22
toastLabel. textColor = . layoverWhite
25
23
toastLabel. textAlignment = . center
@@ -29,15 +27,9 @@ final class Toast {
29
27
toastLabel. clipsToBounds = true
30
28
toastLabel. numberOfLines = 1
31
29
toastLabel. layer. opacity = 0.8
32
- let size : CGSize = toastLabel. intrinsicContentSize
33
- toastLabel. frame = CGRect (
34
- x: ( windowWidth - size. width) / 2 ,
35
- y: ( windowHeight - size. height) / 2 ,
36
- width: size. width,
37
- height: size. height)
38
-
39
- window? . addSubview ( toastLabel)
40
-
30
+ toastLabel. frame. size = toastLabel. intrinsicContentSize
31
+ window. addSubview ( toastLabel)
32
+ toastLabel. center = window. center
41
33
UIView . animate ( withDuration: 2.0 , delay: 0.1 , options: . curveEaseOut, animations: {
42
34
toastLabel. alpha = 0.0
43
35
} , completion: { _ in
0 commit comments