Git Product home page Git Product logo

cfalertviewcontroller's Introduction

#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.

Requirements :

CFAlertViewController works on devices (iPhone and iPad) with iOS 8.0+. It depends on the following Apple frameworks:

  • Foundation.framework
  • UIKit.framework

Install using Cocoapods (recommended)

We assume that your Cocoapods is already configured. If you are new to Cocoapods, have a look at the documentation

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

Install using Source file

  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.
  2. Include CFAlertViewController wherever you need it with #import "CFAlertViewController.h".

Usage :

The above shown alert and actionsheet can easily be implemented using the code snippet given below by some small tweaks ```objective-c // Create Alert CFAlertViewController *alert = [CFAlertViewController alertControllerWithTitle:@"You've hit the limit!" message:@"Looks like you've hit your daily follow/unfollow limit. Upgrade to our paid plan to be able to remove your limits." textAlignment:NSTextAlignmentCenter preferredStyle:CFAlertControllerStyleAlert didDismissAlertHandler:^{ NSLog(@"Alert Dismissed"); }];

// 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;
Title and Message

You can set custom title and message of the alert (pass nil if you don’t need them).

Alignment

You can customise alignment of the title and message. Set the textAlignment property with one of the following values :

NSTextAlignmentLeft,    
NSTextAlignmentRight,    
NSTextAlignmentCenter
Alert Style

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
Header / Footer

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.

  1. Some examples where you can make the use of header in alert (the dollar image is in header)

  1. Some examples where you can make the use of footer in alert

Callback

A block (of type CFAlertViewControllerDismissBlock) gets called when the Alert / Action Sheet is dismissed. You can use it to handle call back.

Actions

+ (nullable instancetype) actionWithTitle:(nonnull NSString *)title
                                    style:(CFAlertActionStyle)style
                                alignment:(CFAlertActionAlignment)alignment
                                    color:(nullable UIColor *)color
                                  handler:(nullable CFAlertActionHandlerBlock)handler
Title

You can set the title of action button to be added.

Action Style

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
Actions Alignment

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,
Callback

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.

cfalertviewcontroller's People

Contributors

vinayak-codigami avatar shardul89 avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.