Skip to content

Commit f584fd4

Browse files
committed
Merge branch 'ready-improvements' into develop
* ready-improvements: Fix tabs Change installation steps Update view controller initializer Update language Enums updated Fix Update first code sample FIX: link to license file Add license tag Add badges to show downloads and pod version
2 parents 63f1e17 + 00ec823 commit f584fd4

1 file changed

Lines changed: 58 additions & 55 deletions

File tree

README.md

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#CFAlertViewController
1+
#CFAlertViewController
2+
[![CocoaPods](https://img.shields.io/cocoapods/v/CFAlertViewController.svg)](https://cocoapods.org/pods/CFAlertViewController)
3+
[![CocoaPods](https://img.shields.io/cocoapods/dt/CFAlertViewController.svg)](https://cocoapods.org/pods/CFAlertViewController)
4+
[![license](https://img.shields.io/github/license/codigami/cfalertviewcontroller.svg)](https://github.com/Codigami/CFAlertViewController/blob/master/README.md)
5+
26
`CFAlertViewController` is a library that helps you display and customise **alerts and action sheets** on iPad and iPhone. It offers screen rotation as well as an adaptive UI support. CFAlertViewController’s functionality is almost similar to the native UIAlertController.
37
<GIF>
48

@@ -14,70 +18,68 @@ We assume that your Cocoapods is already configured. If you are new to Cocoapods
1418

1519
1. Add `pod 'CFAlertViewController'` to your Podfile.
1620
2. Install the pod(s) by running `pod install` in terminal (in folder where `Podfile` file is located).
17-
3. Include CFAlertViewController wherever you need it with `#import "CFAlertViewController.h"`.
1821

1922
#### Install using Source file
20-
1. Open the downloaded project in Xcode, then drag and drop folder named **CFAlertViewController** onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
21-
2. Include CFAlertViewController wherever you need it with `#import "CFAlertViewController.h"`.
23+
Open the downloaded project in Xcode, then drag and drop folder named **CFAlertViewController** onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
2224

2325
## Usage :
2426
<p>
2527
<img src="https://github.com/Codigami/CFAlertViewController/blob/develop/Images/Alert%20%26%20Action%20sheet.png" style="width: 100%" />
2628
</p>
2729
The above shown alert and actionsheet can easily be implemented using the code snippet given below by some small tweaks
28-
```objective-c
30+
```swift
2931
// Create Alert
30-
CFAlertViewController *alert = [CFAlertViewController alertControllerWithTitle:@"You've hit the limit!"
31-
message:@"Looks like you've hit your daily follow/unfollow limit. Upgrade to our paid plan to be able to remove your limits."
32-
textAlignment:NSTextAlignmentCenter
33-
preferredStyle:CFAlertControllerStyleAlert
34-
didDismissAlertHandler:^{
35-
NSLog(@"Alert Dismissed");
36-
}];
32+
var alertController: CFAlertViewController = CFAlertViewController(title: "You've hit the limit",
33+
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,
34+
preferredStyle: .alert) { (didTapBackground) in
35+
print("Alert Dismissed")
36+
if (didTapBackground) {
37+
// Handle background tap here
38+
}
39+
}
40+
41+
var defaultAction = CFAlertAction(title: "UPGRADE",
42+
style: .Default,
43+
alignment: .justified,
44+
backgroundColor: UIColor(red: CGFloat(46.0 / 255.0), green: CGFloat(204.0 / 255.0), blue: CGFloat(113.0 / 255.0), alpha: CGFloat(1)),
45+
textColor: UIColor.white) { (action) in
46+
print("Button with \(action.title) title tapped")
47+
}
3748

38-
// Add Action Button
39-
CFAlertAction *actionDefault = [CFAlertAction actionWithTitle:@"UPGRADE"
40-
style:CFAlertActionStyleDefault
41-
alignment:CFAlertActionAlignmentJustified
42-
color:[UIColor colorWithRed:46.0/255.0 green:204.0/255.0 blue:113.0/255.0 alpha:1]
43-
handler: ^(CFAlertAction *action) {
44-
NSLog(@"Button with %@ title tapped",action.title);
45-
}];
46-
4749
// Add Action Button Into Alert
48-
[alert addAction:actionDefault];
49-
50-
// Present Alert
51-
[self presentViewController:alert animated:YES completion:nil];
50+
alertController.addAction(defaultAction)
51+
52+
self.present(alertController, animated: true, completion: nil)
5253
```
5354
## Customisations :
5455

5556
### Alerts
56-
```objective-c
57-
+ (nonnull instancetype) alertControllerWithTitle:(nullable NSString *)title
58-
message:(nullable NSString *)message
59-
textAlignment:(NSTextAlignment)textAlignment
60-
preferredStyle:(CFAlertControllerStyle)preferredStyle
61-
headerView:(nullable UIView *)headerView
62-
footerView:(nullable UIView *)footerView
63-
didDismissAlertHandler:(nullable CFAlertViewControllerDismissBlock)dismiss;
57+
```swift
58+
convenience init(title: String?,
59+
message: String?,
60+
textAlignment: NSTextAlignment,
61+
preferredStyle: CFAlertControllerStyle,
62+
headerView: UIView?,
63+
footerView: UIView?,
64+
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?)
6465
```
66+
6567
##### Title and Message
6668
You can set custom title and message of the alert (pass nil if you don’t need them).
6769

6870
##### Alignment
6971
You can customise alignment of the title and message. Set the `textAlignment` property with one of the following values :
70-
```objective-c
71-
NSTextAlignmentLeft,
72-
NSTextAlignmentRight,
73-
NSTextAlignmentCenter
72+
```swift
73+
NSTextAlignment.left,
74+
NSTextAlignment.right,
75+
NSTextAlignment.center
7476
```
7577

7678
##### Alert Style
7779
Presentation style of the alert can be customised as Alert or Action sheet. Just set the `preferredStyle` property with one of the following values :
78-
```objective-c
79-
CFAlertControllerStyleAlert,
80-
CFAlertControllerStyleActionSheet
80+
```swift
81+
CFAlertViewController.CFAlertControllerStyle.actionSheet,
82+
CFAlertViewController.CFAlertControllerStyle.alert
8183
```
8284

8385
##### Header / Footer
@@ -97,31 +99,32 @@ CFAlertControllerStyleActionSheet
9799
A block (of type CFAlertViewControllerDismissBlock) gets called when the Alert / Action Sheet is dismissed. You can use it to handle call back.
98100

99101
### Actions
100-
```objective-c
101-
+ (nullable instancetype) actionWithTitle:(nonnull NSString *)title
102-
style:(CFAlertActionStyle)style
103-
alignment:(CFAlertActionAlignment)alignment
104-
color:(nullable UIColor *)color
105-
handler:(nullable CFAlertActionHandlerBlock)handler;
102+
```swift
103+
convenience init(title: String?,
104+
style: CFAlertActionStyle,
105+
alignment: CFAlertActionAlignment,
106+
backgroundColor: UIColor?,
107+
textColor: UIColor?,
108+
handler: CFAlertActionHandlerBlock?)
106109
```
107110
##### Title
108111
You can set the title of action button to be added.
109112

110113
##### Action Style
111114
Configure the style of the action button that is to be added to alert view. Set `style` property of the above method with one of the following Action style
112-
```objective-c
113-
CFAlertActionStyleDefault,
114-
CFAlertActionStyleCancel,
115-
CFAlertActionStyleDestructive
115+
```swift
116+
CFAlertActionStyle.Default,
117+
CFAlertActionStyle.Cancel,
118+
CFAlertActionStyle.Destructive
116119
```
117120

118121
##### Actions Alignment
119122
Configure the alignment of the action button added to the alert view. Set `alignment` property of CFAction constructor with one of the following action types
120-
```objective-c
121-
CFAlertActionAlignmentJustified, // Action Button occupies the full width
122-
CFAlertActionAlignmentRight,
123-
CFAlertActionAlignmentLeft,
124-
CFAlertActionAlignmentCenter
123+
```swift
124+
CFAlertActionAlignment.justified, // Action Button occupies the full width
125+
CFAlertActionAlignment.right,
126+
CFAlertActionAlignment.left,
127+
CFAlertActionAlignment.center
125128
```
126129

127130
##### Callback

0 commit comments

Comments
 (0)