@@ -27,6 +27,12 @@ public class CFAlertViewController: UIViewController {
2727 public static func CF_ALERT_DEFAULT_BACKGROUND_COLOR( ) -> UIColor {
2828 return UIColor ( white: 0.0 , alpha: 0.7 )
2929 }
30+ public static func CF_ALERT_DEFAULT_TITLE_COLOR( ) -> UIColor {
31+ return UIColor . init ( red: 1.0 / 255.0 , green: 51.0 / 255.0 , blue: 86.0 / 255.0 , alpha: 1.0 )
32+ }
33+ public static func CF_ALERT_DEFAULT_MESSAGE_COLOR( ) -> UIColor {
34+ return UIColor . init ( red: 1.0 / 255.0 , green: 51.0 / 255.0 , blue: 86.0 / 255.0 , alpha: 1.0 )
35+ }
3036
3137 // MARK: - Variables
3238 // MARK: Public
@@ -36,14 +42,10 @@ public class CFAlertViewController: UIViewController {
3642 DispatchQueue . main. async ( execute: {
3743 // Position Contraints for Container View
3844 if self . preferredStyle == . actionSheet {
39- // Set Corner Radius
40- self . containerView? . layer. cornerRadius = 6.0
4145 self . containerViewCenterYConstraint? . isActive = false
4246 self . containerViewBottomConstraint? . isActive = true
4347 }
4448 else {
45- // Set Corner Radius
46- self . containerView? . layer. cornerRadius = 8.0
4749 self . containerViewBottomConstraint? . isActive = false
4850 self . containerViewCenterYConstraint? . isActive = true
4951 }
@@ -104,11 +106,15 @@ public class CFAlertViewController: UIViewController {
104106 @IBOutlet public weak var backgroundBlurView : UIVisualEffectView ?
105107 public var shouldDismissOnBackgroundTap : Bool = true // Default is True
106108
107- @IBOutlet public weak var containerView : UIView ? // Reference Container View For Transition
109+ // The view which holds the popup UI
110+ // You can change corner radius or background color of this view for additional customisation
111+ @IBOutlet public weak var containerView : UIView ?
108112
109113 // MARK: Private / Internal
110114 internal var titleString : String ?
115+ internal var titleColor : UIColor = CFAlertViewController . CF_ALERT_DEFAULT_TITLE_COLOR ( )
111116 internal var messageString : String ?
117+ internal var messageColor : UIColor = CFAlertViewController . CF_ALERT_DEFAULT_MESSAGE_COLOR ( )
112118 internal var actionList = [ CFAlertAction] ( )
113119 internal var dismissHandler : CFAlertViewControllerDismissBlock ?
114120 internal var keyboardHeight : CGFloat = 0.0 {
@@ -131,15 +137,17 @@ public class CFAlertViewController: UIViewController {
131137 @IBOutlet internal weak var tableViewHeightConstraint : NSLayoutConstraint ?
132138
133139
134- // MARK: - Initialisation Method
140+ // MARK: - Initialisation Methods
135141 public class func alertController( title: String ? ,
136142 message: String ? ,
137143 textAlignment: NSTextAlignment ,
138144 preferredStyle: CFAlertControllerStyle ,
139145 didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) -> CFAlertViewController {
140146
141147 return CFAlertViewController . alertController ( title: title,
148+ titleColor: nil ,
142149 message: message,
150+ messageColor: nil ,
143151 textAlignment: textAlignment,
144152 preferredStyle: preferredStyle,
145153 headerView: nil ,
@@ -155,6 +163,27 @@ public class CFAlertViewController: UIViewController {
155163 footerView: UIView ? ,
156164 didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) -> CFAlertViewController {
157165
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+ public class func alertController( title: String ? ,
178+ titleColor: UIColor ? ,
179+ message: String ? ,
180+ messageColor: UIColor ? ,
181+ textAlignment: NSTextAlignment ,
182+ preferredStyle: CFAlertControllerStyle ,
183+ headerView: UIView ? ,
184+ footerView: UIView ? ,
185+ didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock ? ) -> CFAlertViewController {
186+
158187 // Get Current Bundle
159188 let bundle = Bundle ( for: CFAlertViewController . self)
160189
@@ -166,7 +195,15 @@ public class CFAlertViewController: UIViewController {
166195 alert. backgroundStyle = . plain
167196 alert. backgroundColor = CF_ALERT_DEFAULT_BACKGROUND_COLOR ( )
168197 alert. titleString = title
198+ if let titleColor = titleColor {
199+ alert. titleColor = titleColor
200+ }
201+
169202 alert. messageString = message
203+ if let messageColor = messageColor {
204+ alert. messageColor = messageColor
205+ }
206+
170207 alert. textAlignment = textAlignment
171208 alert. setHeaderView ( headerView, shouldUpdateContainerFrame: false , withAnimation: false )
172209 alert. setFooterView ( footerView, shouldUpdateContainerFrame: false , withAnimation: false )
@@ -176,10 +213,18 @@ public class CFAlertViewController: UIViewController {
176213 alert. modalPresentationStyle = . custom
177214 alert. transitioningDelegate = alert
178215
216+ // Preload View
217+ if #available( iOS 9 . 0 , * ) {
218+ alert. loadViewIfNeeded ( )
219+ } else {
220+ // Fallback on earlier versions
221+ }
222+
179223 return alert
180224 }
181225
182226
227+
183228 // MARK: - View Life Cycle Methods
184229 internal func loadVariables( ) {
185230
@@ -203,6 +248,17 @@ public class CFAlertViewController: UIViewController {
203248
204249 internal func loadDisplayContent( ) {
205250
251+ // Set Container View Default Background Color
252+ containerView? . backgroundColor = UIColor . white
253+
254+ // Set Container View Default Corner Radius
255+ if preferredStyle == . actionSheet {
256+ containerView? . layer. cornerRadius = 6.0
257+ }
258+ else {
259+ containerView? . layer. cornerRadius = 8.0
260+ }
261+
206262 // Add Tap Gesture Recognizer On View
207263 tapGesture = UITapGestureRecognizer ( target: self , action: #selector( self . viewDidTap) )
208264 view. addGestureRecognizer ( self . tapGesture)
@@ -507,7 +563,7 @@ extension CFAlertViewController: UITableViewDataSource, UITableViewDelegate, CFA
507563 cell = tableView. dequeueReusableCell ( withIdentifier: CFAlertTitleSubtitleTableViewCell . identifier ( ) )
508564 let titleSubtitleCell : CFAlertTitleSubtitleTableViewCell ? = ( cell as? CFAlertTitleSubtitleTableViewCell )
509565 // Set Content
510- titleSubtitleCell? . setTitle ( titleString, subtitle: messageString, alignment: textAlignment!)
566+ titleSubtitleCell? . setTitle ( titleString, titleColor : titleColor , subtitle: messageString, subtitleColor : messageColor , alignment: textAlignment!)
511567 // Set Content Margin
512568 titleSubtitleCell? . contentTopMargin = 20.0
513569 if self . actionList. count <= 0 {
0 commit comments