@@ -32,26 +32,28 @@ Open the downloaded project in Xcode, then drag and drop folder named **CFAlertV
32
32
The above shown alert and actionsheet can easily be implemented using the code snippet given below by some small tweaks
33
33
``` swift
34
34
// Create Alert
35
- var alertController: CFAlertViewController = CFAlertViewController (title : " You've hit the limit" ,
36
- message : " Looks like you've hit your daily follow/unfollow limit. Upgrade to our paid plan to be able to remove your limits." , textAlignment : . center ,
37
- preferredStyle : . alert ) { (didTapBackground) in
38
- print ( " Alert Dismissed " )
39
- if (didTapBackground) {
40
- // Handle background tap here
41
- }
35
+ var alertController: CFAlertViewController = CFAlertViewController. alertController (title : " You've hit the limit" ,
36
+ message : " Looks like you've hit your daily follow/unfollow limit. Upgrade to our paid plan to be able to remove your limits." ,
37
+ textAlignment : . left ,
38
+ preferredStyle : . alert ) { (didTapBackground) in
39
+ if (didTapBackground) {
40
+ // Handle background tap here
41
+ }
42
42
}
43
+
43
44
44
- var defaultAction = CFAlertAction (title : " UPGRADE" ,
45
- style : .Default ,
46
- alignment : .justified ,
47
- backgroundColor : UIColor (red : CGFloat (46.0 / 255.0 ), green : CGFloat (204.0 / 255.0 ), blue : CGFloat (113.0 / 255.0 ), alpha : CGFloat (1 )),
48
- textColor : UIColor.white ) { (action) in
49
- print (" Button with \( action.title ) title tapped" )
45
+ var defaultAction = CFAlertAction. action (title : " UPGRADE" ,
46
+ style : .Default ,
47
+ alignment : .justified ,
48
+ backgroundColor : UIColor (red : CGFloat (46.0 / 255.0 ), green : CGFloat (204.0 / 255.0 ), blue : CGFloat (113.0 / 255.0 ), alpha : CGFloat (1 )),
49
+ textColor : UIColor.white ) { (action) in
50
+ print (" Button with \( action.title ) title tapped" )
50
51
}
51
52
52
53
// Add Action Button Into Alert
53
54
alertController.addAction (defaultAction)
54
-
55
+
56
+ // Present Alert View Controller
55
57
self .present (alertController, animated : true , completion : nil )
56
58
```
57
59
@@ -60,20 +62,24 @@ self.present(alertController, animated: true, completion: nil)
60
62
### Alerts
61
63
62
64
``` swift
63
- convenience init (title : String ? ,
64
- message : String ? ,
65
- textAlignment : NSTextAlignment,
66
- preferredStyle : CFAlertControllerStyle,
67
- headerView : UIView? ,
68
- footerView : UIView? ,
69
- didDismissAlertHandler dismiss : CFAlertViewControllerDismissBlock? )
65
+ public class func alertController (title : String ? ,
66
+ titleColor : UIColor? ,
67
+ message : String ? ,
68
+ messageColor : UIColor? ,
69
+ textAlignment : NSTextAlignment,
70
+ preferredStyle : CFAlertControllerStyle,
71
+ headerView : UIView? ,
72
+ footerView : UIView? ,
73
+ didDismissAlertHandler dismiss : CFAlertViewControllerDismissBlock? ) -> CFAlertViewController
70
74
```
71
75
72
- ##### Title and Message
73
- You can set custom title and message of the alert (pass nil if you don’t need them).
76
+ ##### Title and Message
77
+ You can set a custom title and message text in the alert (pass ` nil ` if you don’t need them).
74
78
75
- ##### Alignment
79
+ ##### Title Color and Message Color
80
+ You can set a custom title and message text color in the alert (pass ` nil ` if you want to use Default color values).
76
81
82
+ ##### Alignment
77
83
You can customise alignment of the title and message. Set the ` textAlignment ` property with one of the following values :
78
84
79
85
``` swift
@@ -121,12 +127,12 @@ A block (of type CFAlertViewControllerDismissBlock) gets called when the Alert /
121
127
122
128
### Actions
123
129
``` swift
124
- convenience init (title : String ? ,
125
- style : CFAlertActionStyle,
126
- alignment : CFAlertActionAlignment,
127
- backgroundColor : UIColor? ,
128
- textColor : UIColor? ,
129
- handler : CFAlertActionHandlerBlock? )
130
+ public class func action (title : String ? ,
131
+ style : CFAlertActionStyle,
132
+ alignment : CFAlertActionAlignment,
133
+ backgroundColor : UIColor? ,
134
+ textColor : UIColor? ,
135
+ handler : CFAlertActionHandlerBlock? ) -> CFAlertAction
130
136
```
131
137
##### Title
132
138
You can set the title of action button to be added.
@@ -151,5 +157,8 @@ Configure the alignment of the action button added to the alert view. Set `align
151
157
##### Callback
152
158
A block (of type CFAlertActionHandlerBlock) gets invoked when action is tapped.
153
159
160
+ ### Container View
161
+ You can also configure the background color or layer related properties (e.g. cornerRadius, borderColor, borderWidth) in the ` containerView ` property.
162
+
154
163
## License
155
164
This code is distributed under the terms and conditions of the MIT license.
0 commit comments