@@ -10,7 +10,7 @@ import UIKit
10
10
11
11
12
12
@objc ( CFAlertViewController)
13
- public class CFAlertViewController : UIViewController {
13
+ open class CFAlertViewController : UIViewController {
14
14
15
15
// MARK: - Declarations
16
16
public typealias CFAlertViewControllerDismissBlock = ( _ isBackgroundTapped: Bool ) -> ( )
@@ -24,13 +24,13 @@ public class CFAlertViewController: UIViewController {
24
24
case plain = 0
25
25
case blur
26
26
}
27
- public static func CF_ALERT_DEFAULT_BACKGROUND_COLOR( ) -> UIColor {
27
+ open static func CF_ALERT_DEFAULT_BACKGROUND_COLOR( ) -> UIColor {
28
28
return UIColor ( white: 0.0 , alpha: 0.7 )
29
29
}
30
- public static func CF_ALERT_DEFAULT_TITLE_COLOR( ) -> UIColor {
30
+ open static func CF_ALERT_DEFAULT_TITLE_COLOR( ) -> UIColor {
31
31
return UIColor . init ( red: 1.0 / 255.0 , green: 51.0 / 255.0 , blue: 86.0 / 255.0 , alpha: 1.0 )
32
32
}
33
- public static func CF_ALERT_DEFAULT_MESSAGE_COLOR( ) -> UIColor {
33
+ open static func CF_ALERT_DEFAULT_MESSAGE_COLOR( ) -> UIColor {
34
34
return UIColor . init ( red: 1.0 / 255.0 , green: 51.0 / 255.0 , blue: 86.0 / 255.0 , alpha: 1.0 )
35
35
}
36
36
@@ -155,25 +155,6 @@ public class CFAlertViewController: UIViewController {
155
155
didDismissAlertHandler: dismiss)
156
156
}
157
157
158
- public class func alertController( title: String ? ,
159
- message: String ? ,
160
- textAlignment: NSTextAlignment ,
161
- preferredStyle: CFAlertControllerStyle ,
162
- headerView: UIView ? ,
163
- footerView: UIView ? ,
164
- didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) -> CFAlertViewController {
165
-
166
- return CFAlertViewController . alertController ( title: title,
167
- titleColor: nil ,
168
- message: message,
169
- messageColor: nil ,
170
- textAlignment: textAlignment,
171
- preferredStyle: preferredStyle,
172
- headerView: headerView,
173
- footerView: footerView,
174
- didDismissAlertHandler: dismiss)
175
- }
176
-
177
158
public class func alertController( title: String ? ,
178
159
titleColor: UIColor ? ,
179
160
message: String ? ,
@@ -184,47 +165,84 @@ public class CFAlertViewController: UIViewController {
184
165
footerView: UIView ? ,
185
166
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) -> CFAlertViewController {
186
167
168
+ // Create New Instance Of Alert Controller
169
+ return CFAlertViewController . init ( title: title,
170
+ titleColor: titleColor,
171
+ message: message,
172
+ messageColor: messageColor,
173
+ textAlignment: textAlignment,
174
+ preferredStyle: preferredStyle,
175
+ headerView: headerView,
176
+ footerView: footerView,
177
+ didDismissAlertHandler: dismiss)
178
+ }
179
+
180
+ public convenience init ( title: String ? ,
181
+ message: String ? ,
182
+ textAlignment: NSTextAlignment ,
183
+ preferredStyle: CFAlertControllerStyle ,
184
+ didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) {
185
+
186
+ // Create New Instance Of Alert Controller
187
+ self . init ( title: title,
188
+ titleColor: nil ,
189
+ message: message,
190
+ messageColor: nil ,
191
+ textAlignment: textAlignment,
192
+ preferredStyle: preferredStyle,
193
+ headerView: nil ,
194
+ footerView: nil ,
195
+ didDismissAlertHandler: dismiss)
196
+ }
197
+
198
+ public convenience init ( title: String ? ,
199
+ titleColor: UIColor ? ,
200
+ message: String ? ,
201
+ messageColor: UIColor ? ,
202
+ textAlignment: NSTextAlignment ,
203
+ preferredStyle: CFAlertControllerStyle ,
204
+ headerView: UIView ? ,
205
+ footerView: UIView ? ,
206
+ didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) {
207
+
187
208
// Get Current Bundle
188
209
let bundle = Bundle ( for: CFAlertViewController . self)
189
210
190
211
// Create New Instance Of Alert Controller
191
- let alert = CFAlertViewController . init ( nibName: " CFAlertViewController " , bundle: bundle)
212
+ self . init ( nibName: " CFAlertViewController " , bundle: bundle)
192
213
193
214
// Assign Properties
194
- alert . preferredStyle = preferredStyle
195
- alert . backgroundStyle = . plain
196
- alert . backgroundColor = CF_ALERT_DEFAULT_BACKGROUND_COLOR ( )
197
- alert . titleString = title
215
+ self . preferredStyle = preferredStyle
216
+ backgroundStyle = . plain
217
+ backgroundColor = CFAlertViewController . CF_ALERT_DEFAULT_BACKGROUND_COLOR ( )
218
+ titleString = title
198
219
if let titleColor = titleColor {
199
- alert . titleColor = titleColor
220
+ self . titleColor = titleColor
200
221
}
201
222
202
- alert . messageString = message
223
+ messageString = message
203
224
if let messageColor = messageColor {
204
- alert . messageColor = messageColor
225
+ self . messageColor = messageColor
205
226
}
206
227
207
- alert . textAlignment = textAlignment
208
- alert . setHeaderView ( headerView, shouldUpdateContainerFrame: false , withAnimation: false )
209
- alert . setFooterView ( footerView, shouldUpdateContainerFrame: false , withAnimation: false )
210
- alert . dismissHandler = dismiss
228
+ self . textAlignment = textAlignment
229
+ setHeaderView ( headerView, shouldUpdateContainerFrame: false , withAnimation: false )
230
+ setFooterView ( footerView, shouldUpdateContainerFrame: false , withAnimation: false )
231
+ dismissHandler = dismiss
211
232
212
233
// Custom Presentation
213
- alert . modalPresentationStyle = . custom
214
- alert . transitioningDelegate = alert
234
+ modalPresentationStyle = . custom
235
+ transitioningDelegate = self
215
236
216
237
// Preload View
217
238
if #available( iOS 9 . 0 , * ) {
218
- alert . loadViewIfNeeded ( )
239
+ loadViewIfNeeded ( )
219
240
} else {
220
241
// Fallback on earlier versions
221
242
}
222
-
223
- return alert
224
243
}
225
244
226
245
227
-
228
246
// MARK: - View Life Cycle Methods
229
247
internal func loadVariables( ) {
230
248
@@ -264,7 +282,7 @@ public class CFAlertViewController: UIViewController {
264
282
view. addGestureRecognizer ( self . tapGesture)
265
283
}
266
284
267
- public override func viewDidLoad( ) {
285
+ open override func viewDidLoad( ) {
268
286
super. viewDidLoad ( )
269
287
270
288
// Load Variables
@@ -274,7 +292,7 @@ public class CFAlertViewController: UIViewController {
274
292
loadDisplayContent ( )
275
293
}
276
294
277
- public override func viewWillAppear( _ animated: Bool ) {
295
+ open override func viewWillAppear( _ animated: Bool ) {
278
296
super. viewWillAppear ( animated)
279
297
280
298
// Update UI
@@ -481,7 +499,7 @@ public class CFAlertViewController: UIViewController {
481
499
482
500
483
501
// MARK: - View Rotation / Size Change Method
484
- public override func viewWillTransition( to size: CGSize , with coordinator: UIViewControllerTransitionCoordinator ) {
502
+ open override func viewWillTransition( to size: CGSize , with coordinator: UIViewControllerTransitionCoordinator ) {
485
503
super. viewWillTransition ( to: size, with: coordinator)
486
504
// Code here will execute before the rotation begins.
487
505
// Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:]
@@ -498,7 +516,7 @@ public class CFAlertViewController: UIViewController {
498
516
499
517
500
518
// MARK: - Key Value Observers
501
- public override func observeValue( forKeyPath keyPath: String ? , of object: Any ? , change: [ NSKeyValueChangeKey : Any ] ? , context: UnsafeMutableRawPointer ? ) {
519
+ open override func observeValue( forKeyPath keyPath: String ? , of object: Any ? , change: [ NSKeyValueChangeKey : Any ] ? , context: UnsafeMutableRawPointer ? ) {
502
520
if ( keyPath == " contentSize " ) {
503
521
// Update Container View Frame Without Animation
504
522
updateContainerViewFrame ( withAnimation: false )
0 commit comments