@@ -33,7 +33,7 @@ public enum ToastStyle {
3333
3434extension UIViewController {
3535
36- public func MotionToast( message: String , toastType: ToastType , duration: ToastDuration ? = . short, toastStyle: ToastStyle ? = . style_vibrant, toastGravity: ToastGravity ? = . bottom, toastCornerRadius: Int ? = 0 ) {
36+ public func MotionToast( message: String , toastType: ToastType , duration: ToastDuration ? = . short, toastStyle: ToastStyle ? = . style_vibrant, toastGravity: ToastGravity ? = . bottom, toastCornerRadius: Int ? = 0 , pulseEffect : Bool ? = true ) {
3737
3838 guard let window = UIApplication . shared. connectedScenes. filter ( { $0. activationState == . foregroundActive} ) . map ( { $0 as? UIWindowScene } )
3939 . compactMap ( { $0} ) . first? . windows. filter ( { $0. isKeyWindow} ) . first else { return }
@@ -47,8 +47,8 @@ extension UIViewController {
4747
4848 var toastView : UIView ?
4949 switch toastStyle {
50- case . style_vibrant: toastView = toastStyle_vibrant ( message: message, toastType: toastType, toastGravity: toastGravity!, toastCornerRadius: toastCornerRadius!, view: view) ;break
51- case . style_pale: toastView = toastStyle_pale ( message: message, toastType: toastType, toastGravity: toastGravity!, view: view) ;break
50+ case . style_vibrant: toastView = toastStyle_vibrant ( message: message, toastType: toastType, toastGravity: toastGravity!, toastCornerRadius: toastCornerRadius!, view: view, pulseEffect : pulseEffect! ) ;break
51+ case . style_pale: toastView = toastStyle_pale ( message: message, toastType: toastType, toastGravity: toastGravity!, view: view, pulseEffect : pulseEffect! ) ;break
5252 case . none: break
5353 }
5454
@@ -60,9 +60,84 @@ extension UIViewController {
6060 toastView!. removeFromSuperview ( )
6161 }
6262 }
63+
64+ public func MotionToast_Customisation( header: String , message: String , headerColor: UIColor , messageColor: UIColor ,
65+ primary_color: UIColor , secondary_color: UIColor , icon_image: UIImage ,
66+ duration: ToastDuration ? = . short, toastStyle: ToastStyle ? = . style_vibrant,
67+ toastGravity: ToastGravity ? = . bottom, toastCornerRadius: Int ? = 0 , pulseEffect: Bool ? = true ) {
68+
69+ guard let window = UIApplication . shared. connectedScenes. filter ( { $0. activationState == . foregroundActive} ) . map ( { $0 as? UIWindowScene } )
70+ . compactMap ( { $0} ) . first? . windows. filter ( { $0. isKeyWindow} ) . first else { return }
71+
72+ var toastDuration = 2.0
73+ switch duration {
74+ case . short: toastDuration = 2.0 ;break
75+ case . long: toastDuration = 4.0 ;break
76+ case . none: break
77+ }
78+
79+ var toastUIView : UIView ?
80+ switch toastStyle {
81+ case . style_vibrant:
82+
83+ var gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 )
84+ switch toastGravity! {
85+ case . top: gravity = CGRect ( x: 0.0 , y: 80.0 , width: view. frame. width, height: 83.0 ) ;break
86+ case . centre: gravity = CGRect ( x: 0.0 , y: ( ( view. frame. height / 2 ) - 41 ) , width: view. frame. width, height: 83.0 ) ;break
87+ case . bottom: gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 ) ;break
88+ }
89+
90+ let toastView = MTVibrant ( frame: gravity)
91+ if pulseEffect! { toastView. addPulseEffect ( ) }
92+ toastView. toastView. layer. cornerRadius = CGFloat ( toastCornerRadius!)
93+
94+ toastView. headLabel. text = header
95+ toastView. headLabel. textColor = headerColor
96+ toastView. msgLabel. text = message
97+ toastView. msgLabel. textColor = messageColor
98+ toastView. circleImg. image = icon_image
99+ toastView. toastView. backgroundColor = primary_color
100+ toastView. circleView. backgroundColor = secondary_color
101+ toastUIView = toastView
102+ break
103+
104+ case . style_pale:
105+
106+ var gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 )
107+ switch toastGravity! {
108+ case . top: gravity = CGRect ( x: 0.0 , y: 80.0 , width: view. frame. width, height: 83.0 ) ;break
109+ case . centre: gravity = CGRect ( x: 0.0 , y: ( ( view. frame. height / 2 ) - 41 ) , width: view. frame. width, height: 83.0 ) ;break
110+ case . bottom: gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 ) ;break
111+ }
112+
113+ let toastView = MTPale ( frame: gravity)
114+ if pulseEffect! { toastView. addPulseEffect ( ) }
115+ toastView. toastView. layer. cornerRadius = CGFloat ( toastCornerRadius!)
116+
117+ toastView. headLabel. text = header
118+ toastView. headLabel. textColor = headerColor
119+ toastView. msgLabel. text = message
120+ toastView. msgLabel. textColor = messageColor
121+ toastView. circleImg. image = icon_image
122+ toastView. toastView. backgroundColor = primary_color
123+ toastView. circleView. backgroundColor = secondary_color
124+ toastView. sideBarView. backgroundColor = secondary_color
125+ toastUIView = toastView
126+ break
127+ case . none: break
128+ }
129+
130+ window. addSubview ( toastUIView!)
131+
132+ UIView . animate ( withDuration: 1.0 , delay: toastDuration, animations: {
133+ toastUIView!. alpha = 0
134+ } ) { ( _) in
135+ toastUIView!. removeFromSuperview ( )
136+ }
137+ }
63138}
64139
65- func toastStyle_vibrant( message: String , toastType: ToastType , toastGravity: ToastGravity , toastCornerRadius: Int , view: UIView ) -> MTVibrant {
140+ func toastStyle_vibrant( message: String , toastType: ToastType , toastGravity: ToastGravity , toastCornerRadius: Int , view: UIView , pulseEffect : Bool ) -> MTVibrant {
66141
67142 var gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 )
68143 switch toastGravity {
@@ -73,12 +148,13 @@ func toastStyle_vibrant(message: String, toastType: ToastType, toastGravity: Toa
73148
74149 let toastView = MTVibrant ( frame: gravity)
75150 toastView. setupViews ( toastType: toastType)
151+ if pulseEffect { toastView. addPulseEffect ( ) }
76152 toastView. msgLabel. text = message
77153 toastView. toastView. layer. cornerRadius = CGFloat ( toastCornerRadius)
78154 return toastView
79155}
80156
81- func toastStyle_pale( message: String , toastType: ToastType , toastGravity: ToastGravity , view: UIView ) -> MTPale {
157+ func toastStyle_pale( message: String , toastType: ToastType , toastGravity: ToastGravity , view: UIView , pulseEffect : Bool ) -> MTPale {
82158
83159 var gravity = CGRect ( x: 0.0 , y: view. frame. height - 130.0 , width: view. frame. width, height: 83.0 )
84160 switch toastGravity {
@@ -89,6 +165,7 @@ func toastStyle_pale(message: String, toastType: ToastType, toastGravity: ToastG
89165
90166 let toastView = MTPale ( frame: gravity)
91167 toastView. setupViews ( toastType: toastType)
168+ if pulseEffect { toastView. addPulseEffect ( ) }
92169 toastView. msgLabel. text = message
93170 return toastView
94171}
0 commit comments