#CFAlertViewController
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.
CFAlertViewController works on devices (iPhone and iPad) with iOS 8.0+. It depends on the following Apple frameworks:
- Foundation.framework
- UIKit.framework
We assume that your Cocoapods is already configured. If you are new to Cocoapods, have a look at the documentation
- Add
pod 'CFAlertViewController'
to your Podfile. - Install the pod(s) by running
pod install
in terminal (in folder wherePodfile
file is located). - Include CFAlertViewController wherever you need it with
#import "CFAlertViewController.h"
.
- 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.
- Include CFAlertViewController wherever you need it with
#import "CFAlertViewController.h"
.
// Add Action Button CFAlertAction *actionDefault = [CFAlertAction actionWithTitle:@"UPGRADE" style:CFAlertActionStyleDefault alignment:CFAlertActionAlignmentJustified color:[UIColor colorWithRed:46.0/255.0 green:204.0/255.0 blue:113.0/255.0 alpha:1] handler: ^(CFAlertAction *action) { NSLog(@"Button with %@ title tapped",action.title); }];
// Add Action Button Into Alert [alert addAction:actionDefault];
// Present Alert [self presentViewController:alert animated:YES completion:nil];
## Customisations :
### Alerts
```objective-c
+ (nonnull instancetype) alertControllerWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
textAlignment:(NSTextAlignment)textAlignment
preferredStyle:(CFAlertControllerStyle)preferredStyle
headerView:(nullable UIView *)headerView
footerView:(nullable UIView *)footerView
didDismissAlertHandler:(nullable CFAlertViewControllerDismissBlock)dismiss;
You can set custom title and message of the alert (pass nil if you don’t need them).
You can customise alignment of the title and message. Set the textAlignment
property with one of the following values :
NSTextAlignmentLeft,
NSTextAlignmentRight,
NSTextAlignmentCenter
Presentation style of the alert can be customised as Alert or Action sheet. Just set the preferredStyle
property with one of the following values :
CFAlertControllerStyleAlert,
CFAlertControllerStyleActionSheet
You can add header and footer to the alert. Set properties headerView
and footerView
with custom views (subclass of UIView). You can pass nil to this properties to opt them out.
- Some examples where you can make the use of header in alert (the dollar image is in header)
- Some examples where you can make the use of footer in alert
A block (of type CFAlertViewControllerDismissBlock) gets called when the Alert / Action Sheet is dismissed. You can use it to handle call back.
+ (nullable instancetype) actionWithTitle:(nonnull NSString *)title
style:(CFAlertActionStyle)style
alignment:(CFAlertActionAlignment)alignment
color:(nullable UIColor *)color
handler:(nullable CFAlertActionHandlerBlock)handler
You can set the title of action button to be added.
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
CFAlertActionStyleDefault,
CFAlertActionStyleCancel,
CFAlertActionStyleDestructive
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
CFAlertActionAlignmentJustified, // Action Button occupies the full width
CFAlertActionAlignmentRight,
CFAlertActionAlignmentLeft,
CFAlertActionAlignmentCenter,
A block (of type CFAlertActionHandlerBlock) gets invoked when action is tapped.
##License This code is distributed under the terms and conditions of the MIT license.