It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

Overview

 CFAlertViewController

CocoaPods CocoaPods license Twitter URL

CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and iPhone. It offers screen rotation as well as an adaptive UI support. CFAlertViewController’s API is almost similar to the native UIAlertController but it has a lot more functionalities than the native UIAlertController.

You can also check out this library for Android Android by clicking here

Types of use cases:

Demo 1

Configuration options:

Demo 2

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

Install using Source file

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.

Usage :

The above shown alert can easily be implemented using the code snippet:

// Create Alet View Controller
let alertController = CFAlertViewController(title: "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: .left,
                                            preferredStyle: .notification,
                                            didDismissAlertHandler: nil)

// Create Upgrade Action
let defaultAction = CFAlertAction(title: "UPGRADE",
                                  style: .Default,
                                  alignment: .right,
                                  backgroundColor: UIColor(red: CGFloat(46.0 / 255.0), green: CGFloat(204.0 / 255.0), blue: CGFloat(113.0 / 255.0), alpha: CGFloat(1)),
                                  textColor: nil,
                                  handler: { (action) in
                                    print("Button with title '" + action.title! + "' tapped")
})

// Add Action Button Into Alert
alertController.addAction(defaultAction)

// Present Alert View Controller
present(alertController, animated: true, completion: nil)

Customisations :

Alerts

public convenience init(title: String?,
                        titleColor: UIColor?,
                        message: String?,
                        messageColor: UIColor?,
                        textAlignment: NSTextAlignment,
                        preferredStyle: CFAlertControllerStyle,
                        headerView: UIView?,
                        footerView: UIView?,
                        didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?)
Title and Message

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

Title Color and Message Color

You can set a custom title and message text color in the alert (pass nil if you want to use Default color values).

Alignment

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

NSTextAlignment.left,    
NSTextAlignment.right,    
NSTextAlignment.center,
NSTextAlignment.justified,
NSTextAlignment.natural
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 :

CFAlertControllerStyle.alert,
CFAlertControllerStyle.actionSheet,
CFAlertControllerStyle.notification
Background style

Background (overlay) of alert/action sheet can be blurred (Useful for security reasons in case the background needs to be hidden). Default value is plain. You can customize the blur style using backgroundBlurView property of type UIVisualEffectView. Update backgroundStyle property with one of the following enum values:

CFAlertControllerBackgroundStyle.plain,
CFAlertControllerBackgroundStyle.blur
Background color

You can change the background (overlay) color of the alert/actionsheet using the property backgroundColor.

Dismiss on background tap

By default, the alert gets dismissed after tapping on the background (overlay). Change shouldDismissOnBackgroundTap property to false to disable it. Do remember that whenever shouldDismissOnBackgroundTap property is set to true, the user will be able to dismiss ActionSheet or Notification using interactive swipe gesture.

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 dismiss call back. It also gives you a reason of dismiss with below mentioned enums,

CFAlertControllerDismissReason.none,
CFAlertControllerDismissReason.onActionTap
CFAlertControllerDismissReason.onBackgroundTap
CFAlertControllerDismissReason.onInteractiveTransition

Actions

public convenience init(title: String?,
                        style: CFAlertActionStyle,
                        alignment: CFAlertActionAlignment,
                        backgroundColor: UIColor?,
                        textColor: UIColor?,
                        handler: CFAlertActionHandlerBlock?)
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

 CFAlertActionStyle.Default,
 CFAlertActionStyle.Cancel,
 CFAlertActionStyle.Destructive
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

 CFAlertActionAlignment.justified,   // Action Button occupies the full width
 CFAlertActionAlignment.right,
 CFAlertActionAlignment.left,
 CFAlertActionAlignment.center
Callback

A block (of type CFAlertActionHandlerBlock) gets invoked when action is tapped.

Container View

You can also configure the background color or layer related properties (e.g. cornerRadius, borderColor, borderWidth) in the containerView property.

License

This code is distributed under the terms and conditions of the MIT license.

Comments
  • Swift 4 warnings

    Swift 4 warnings

    Issue Info

    Info | Value | -------------------------------|-------------------------------------| Platform Name | ios Platform Version | 11.0 CFAlertViewController Version | 232 Integration Method | manually Xcode Version | Xcode 9.0 Repro rate | all the time

    Issue Description and Steps

    I have plenty of this warnings in swift 4: When calling this function in Swift 4 or later, you must pass a '()' tuple; did you mean for the input type to be '()'?

    It would be great if you can solve that, thanks.

    opened by dtomicAZ 4
  • Disable background tap to dismiss

    Disable background tap to dismiss

    Would be good for future users to know in your documentation they can:

    alert.shouldDismissOnBackgroundTap = NO;

    to disable the default behavior allowing background tap to dismiss.

    opened by rjpalermo1 2
  • Feature Request: TextFields

    Feature Request: TextFields

    We can add a textfield for user input to the header of a UIAlertController in iOS, using "addTextFieldWithConfigurationHandler:"

    Is there any way to do something similar with a CFAlertViewController?

    It would be great to be able to do this, so the interfaces can be made to match.

    opened by Solublepeter 1
  • containerView blocking UITapGesture

    containerView blocking UITapGesture

    Info | Value | -------------------------------|-------------------------------------| Platform Name | ios Platform Version | 11 CFAlertViewController Version | 3.0 Integration Method | cocoapods Xcode Version | Xcode 9.2 Repro rate | 100% Repro with our demo prj | no

    Issue Description and Steps

    I am currently using CFAlertController to present a view that allows the user to enter a star rating via Cosmos and a review using a UITextView. What is happening is that the viewDidTap from CFAlert is eating the UITapGesture needed by the Cosmos star rating to update the stars.

    Is it possible to make this overridable? Or is there a known way around having the alert eat the UITapGesture?

    opened by dcortright 1
  • Wrong tutorial on Swift 3

    Wrong tutorial on Swift 3

    Initializer is CFAlertViewController.alertController(parameters) rather than CFAlertViewController(parameters)

    Same with defaultAction which is CFAlertAction.action(parameters) rather than CFAlertAction(parameters)

    opened by alberttai1 1
  • Warning

    Warning "incompatible pointer to integer" in CustomFooterView.m

    Xcode 8.3, iOS 10.3, simulator

    On compilation, get a warning in CustomFooterView.m:

    warning reads: " Incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'UIView * _Nullable'"

    from this line: // Update Header Display State self.shouldDisplayHeader = self.alertController.headerView;

    opened by Solublepeter 1
  • Current version leaks in several places when alert is shown

    Current version leaks in several places when alert is shown

    iOS 10.3 on simulated iPhone 7 plus or real iPhone 6S Xcode 8.3 repro 100%

    Observed when the library was integrated into my code, but you can see this easily in the demo- as follows:

    Download current .ZIP version, and tap CFAlertViewControllerDemo.xcodeproj Profile the app in Leaks mode Tap "Show" in the app, without changing any switches. Observe a leak every time

    Trace file is too large to upload

    opened by Solublepeter 1
  • Clearing UITextfields

    Clearing UITextfields

    Nice clean alert you got here I would like to put into my project...

    After quite some time getting the old alerts replaced with these alerts I was humming right along...until I noticed that when an Alert is dismissed it clears out data in all my UITextfields in my view controller....

    ;(

    opened by rjpalermo1 1
  • Remove unneeded debug print statement

    Remove unneeded debug print statement

    New Pull Request Checklist

    • [X] I have read and understood the CONTRIBUTING guide

    • [X] I have read the Documentation

    • [X] I have searched for a similar pull request in the project and found none

    • [X] I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

    • [X] I have added the required tests to prove the fix/feature I am adding

    • [X] I have updated the documentation (if necessary)

    • [X] I have run the tests and they pass

    • [X] I have run the lint and it passes (pod lib lint)

    This merge request fixes / reffers to the following issues: none

    Pull Request Description

    This removes an unneeded debug statement that is presumably accidentally included in the master branch.

    opened by jmschonfeld 0
  • Fix gh-7: Avoid leak from cell delegate strong reference.

    Fix gh-7: Avoid leak from cell delegate strong reference.

    New Pull Request Checklist

    • [x] I have read and understood the CONTRIBUTING guide

    • [x] I have read the Documentation

    • [x] I have searched for a similar pull request in the project and found none

    • [x] I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

    • [ ] I have added the required tests to prove the fix/feature I am adding

    • [ ] I have updated the documentation (if necessary)

    • [ ] I have run the tests and they pass

    • [x] I have run the lint and it passes (pod lib lint)

    This merge request fixes / reffers to the following issues:

    • 7

    Pull Request Description

    The issue mentions a leak produced by simply using the class. A strong reference from the Alert cell was at least one place where the alert class was held.

    screen shot 2017-08-25 at 5 02 48 pm

    opened by chefren 0
  • Adding SPM Support

    Adding SPM Support

    Commit 1:

    • Adding Package.swift for SPM Support.
    • Adding .gitignore
    • Fixing compiler warnings.
    • Adding a bundle extension for a current variable. Which returns the bundle for SPM or CocoaPods.

    Commit 2:

    • Updating README.md to include SPM installation steps.

    New Pull Request Checklist

    • [x] I have read and understood the CONTRIBUTING guide

    • [x] I have read the Documentation

    • [x] I have searched for a similar pull request in the project and found none

    • [x] I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

    • [x] I have added the required tests to prove the fix/feature I am adding

    • [x] I have updated the documentation (if necessary)

    • [x] I have run the tests and they pass

    • [x] I have run the lint and it passes (pod lib lint)

    This merge request fixes / reffers to the following issues: ...

    opened by afnanm1999 0
  • fix dead image link

    fix dead image link

    New Pull Request Checklist

    • [ ] I have read and understood the CONTRIBUTING guide

    • [ ] I have read the Documentation

    • [ ] I have searched for a similar pull request in the project and found none

    • [ ] I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

    • [ ] I have added the required tests to prove the fix/feature I am adding

    • [ ] I have updated the documentation (if necessary)

    • [ ] I have run the tests and they pass

    • [ ] I have run the lint and it passes (pod lib lint)

    This merge request fixes / reffers to the following issues: ...

    Pull Request Description

    ...

    opened by computingfreak 0
  • How to change the width of the alert?

    How to change the width of the alert?

    New Issue Checklist

    Issue Info

    Info | Value | -------------------------------|-------------------------------------| Platform Name | e.g. ios Platform Version | e.g. 8.0 CFAlertViewController Version | e.g. 2.1.1 Integration Method | e.g. cocoapods / manually Xcode Version | e.g. Xcode 11.0 Repro rate | e.g. all the time (100%) / sometimes x% / only once Repro with our demo prj | e.g. does it happen with our demo project? Demo project link | e.g. link to a demo project that highlights the issue

    Issue Description and Steps

    Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

    opened by dosymbaev 0
  • Incorrect module in xib

    Incorrect module in xib

    Hi,

    The CFAlertTitleSubtitleTableViewCell.xib and CFAlertViewController.xib files have CFAlertViewControllerDemo setup as the Module instead of CFAlertViewController.

    It works in the demo for obvious reasons but when importing into other projects it doesn't. Small oversight while testing?

    opened by ghost 0
  • Add the possibility to update the alert while is visible to the user

    Add the possibility to update the alert while is visible to the user

    New Issue Checklist

    Issue Info

    Info | Value | -------------------------------|-------------------------------------| Platform Name | ios Platform Version | 12.0 CFAlertViewController Version | 3.1 Integration Method | cocoapods Xcode Version | Xcode 10.1

    Issue Description and Steps

    It would be nice to have the possibility to change some alert properties dinamically, from a background thread while the alert is visible to the user (e.g. title, message).

    opened by lechuckcaptain 0
Releases(v3.1)
  • v3.1(Sep 16, 2018)

  • v3.0(Sep 27, 2017)

    What's New:

    1. Swift 4 compatibility added
    2. Introduced new notification style
    3. Now users can use interactive gesture to dismiss notifications and action sheets when shouldDismissOnBackgroundTap property is set to true
    4. iPhone X compatibility added
    Source code(tar.gz)
    Source code(zip)
  • v2.3(Jun 9, 2017)

  • v2.2(Jun 8, 2017)

    What's New: • You can now configure the background color or layer related properties (e.g. cornerRadius, borderColor, borderWidth) in the containerView property. • You can set a custom title and message text color in the alert view.

    This can open up a lot more possibilities of configuration. You can even completely change the way popup looks in your app.

    Source code(tar.gz)
    Source code(zip)
  • v2.1(Mar 15, 2017)

    What's New: • Background Style property added (Plain & Blur) • Background Color property added

    We have also updated the Demo Project to showcase the dynamic capabilities of this library better.

    Source code(tar.gz)
    Source code(zip)
  • v2.0.5(Mar 15, 2017)

    In this version, we have completely rewritten the whole library in Swift 3.0. Don't worry, you can still use this library with your Obj-C / (Obj-C+Swift) projects.

    Source code(tar.gz)
    Source code(zip)
Owner
Crowdfire Inc.
Crowdfire is the world's simplest and most affordable social media management platform
Crowdfire Inc.
zekunyan 608 Dec 30, 2022
Display Apple system-like self-hiding status alerts. It is well suited for notifying user without interrupting user flow in iOS-like way.

StatusAlert is being sponsored by the following tool; please help to support us by takin a look and signing up to a free trial. Dependency managers Fe

Yehor Miroshnychenko 841 Dec 6, 2022
Action sheet allows including your custom views and buttons.

CustomizableActionSheet Action sheet allows including your custom views and buttons. Installation CocoaPods Edit your Podfile: pod 'CustomizableAction

Ryuta Kibe 191 Nov 26, 2021
Custom-action-sheet- - Custom action sheet with swift

Custom-action-sheet- Usage let alertController: UIAlertControllerDimmed = UIAler

Girisankar G 0 Jan 19, 2022
BottomSheet makes it easy to add custom bottom sheets to your SwiftUI apps.

BottomSheet About BottomSheet BottomSheet makes it easy to add custom bottom sheets to your SwiftUI apps. The result can look like this...or completel

Daniel Saidi 174 Jan 2, 2023
an extension library for SwiftUI sheets.

SheetKit SheetKit is an extension library for SwiftUI sheets. 中文版说明 with Picture What is SheetKit SheetKit is a library of extensions for SwiftUI moda

东坡肘子 65 Dec 31, 2022
DropView - A SwiftUI library to display Apple Pencil and Pasteboard-like alerts on iOS.

DropView is a SwiftUI-based library to display alerts inspired by the Apple Pencil and pasteboard stock ones.

Stefano Bertagno 46 Dec 4, 2022
BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

BPStatusBarAlert BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

Ben.Park 131 Aug 12, 2022
SwiftUI native-like onboarding sheets

Welcome Sheet Welcome sheet for swiftUI enables incredibly easy way for creating onboarding screens, update notes, or whatever you imagine! The main i

Jakub Florek 43 Dec 29, 2022
PageSheet - Customizable sheets using UISheetPresentationController in SwiftUI

PageSheet Customizable sheet presentations in SwiftUI. Using UISheetPresentation

Eric Lewis 50 Oct 7, 2022
Share-sheet-example - A sample project that reproduces an issue with Share Sheets

Hello, DTS! This project demonstrates the issue I'm having with the Share Sheet.

Marcos Tanaka 0 Feb 11, 2022
iOS tweak to display toasts for Low Power alerts and charging

Electrode iOS tweak to display toasts for Low Power alerts and charging. Localization Want to help translate Electrode to your language? Sumbit a pull

null 8 Sep 7, 2022
iOS / Objective C: an extremely simple UIAlertView alternative

RKDropdownAlert an extremely simple (and customizeable) alert alternative based on Facebook's app Slingshot, and inspiration from SVProgressHUD (yes,

Richard Kim 1.5k Nov 20, 2022
Advance animated alerts for iOS written in Swift

LIHAlert LIHAlert provides animated banners for iOS. Updated to Swift 3 Demo Project The LIHAlert workspace contains a demo project, also used for dev

null 37 Dec 9, 2022
Bursts 🔥 A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI

Bursts ?? A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI Features iOS 10+ Can be used in UIKit and SwiftUI applications Lig

Jovins 11 Apr 22, 2022
A µFramework for showing alerts like the one used when copying from pasteboard or connecting Apple pencil

Drops ?? A µFramework for showing alerts like the one used when copying from pasteboard or connecting Apple pencil. Features iOS 10+ Can be used in Sw

Omar Albeik 709 Dec 29, 2022
Easily create different alerts in SwiftUI

AlertWizard ????‍♂️ This package lets you easily create different alerts in SwiftUI with the call of a single function. As this is my first package th

null 3 Jun 3, 2021
Create Apple-like alerts & toasts using SwiftUI

AlertToast-SwiftUI Present Apple-like alert & toast in SwiftUI ?? Example ?? Overview Currently in SwiftUI, the only way to inform the user about some

Elai Zuberman 1.1k Dec 29, 2022
🚨Use the iPhone X Notch to display alerts. 🚨

NotchyAlert Prerequisites Xcode 9.x Swift 4.x iPhone X Simulator/Device Demo Installation Cocoapods To install NotchyAlert using Cocoapods, add the fo

Sofiane Beors 70 Nov 20, 2022