Skip to content
A simple, customizable dropdown alert written in Swift 4.2
Swift Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CRDropdownAlert/Classes
.swift-version
CHANGELOG.md
CONTRIBUTING.md
CRDropdownAlert.podspec
LICENSE
README.md

README.md

CRDropdownAlert

Version License Platform

A clean, customizable Swift alternative to RKDropdownAlert and DropdownAlert that supports custom views. Much credit to each of their contributors, especially DropdownAlert.

Overview

This project was inspired by RKDropdownAlert and DropdownAlert. It combines the best of each of them.

  • Written in Swift 4.2 (at the time of writing this, DropdownAlert had not yet been updated to Swift 3)
  • Responsive - Uses Autolayout
  • Touch Activated - Supports delegates for responding to user clicks
  • Supports custom views - Don't restrict yourself to a title and a message. You can create a custom view and hand it off to CRDropdownAlert.

Usage

CRDropdownAlert comes with 3 animation types, Basic, Spring, and Custom:

/**
Animation types the dropdown can be presented with.

- Basic:  Basic, simple animation.
- Spring: Spring animation.
- Custom: Custom animation.
*/
public enum AnimationType {
    case Basic(timingFunction: CAMediaTimingFunction)
    case Spring(bounce: CGFloat, speed: CGFloat)
    case Custom(POPPropertyAnimation)
}

Example (the args besides title and message are optional):

CRDropdownAlert.show(animationType: .Basic(timingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)), title: "New Message", message: "I'm on my way!")

Customization

The following class level properties are customizable:

class var defaultBackgroundColor: UIColor
class var defaultTextColor: UIColor 
class var defaultTitle: String
class var defaultMessage: String
class var defaultAnimationDuration: Double
class var defaultDuration: Double
class var defaultTitleFont: UIFont
class var defaultMessageFont: UIFont
class var defaultFontSize: CGFloat

DropdownAlert claims that the size of the alert will be always be greater than or equal to the size of your content, but I've found that to not always be the case. CRDropdownAlert fixes this by allowing message line wrapping. Some default layout improvements have also been made, including spacing, borders, and bolding.

To customize a particular attribute:

DropdownAlert.defaultHeight = 110
DropdownAlert.defaultBackgroundColor = UIColor.blueColor()

To use a custom view rather than the built-in title and message labels (the args besides view are optional):

CRDropdownAlert.show(animationType: .Spring(bounce: 0.5, speed: 0.5), view: customView, backgroundColor: .white, duration: 3);

For example, this is how I create a progress bar in a CRDropdownAlert:

let parentView = UIView.init();
let progressView = UIProgressView(progressViewStyle: .default);

progressView.translatesAutoresizingMaskIntoConstraints = false;

parentView.addConstraint(NSLayoutConstraint(item: progressView, attribute: .left, relatedBy: .equal, toItem: parentView, attribute: .left, multiplier: 1, constant: 0));
parentView.addConstraint(NSLayoutConstraint(item: progressView, attribute: .right, relatedBy: .equal, toItem: parentView, attribute: .right, multiplier: 1, constant: 0));
parentView.addConstraint(NSLayoutConstraint(item: progressView, attribute: .top, relatedBy: .equal, toItem: parentView, attribute: .top, multiplier: 1, constant: 10));
parentView.addConstraint(NSLayoutConstraint(item: progressView, attribute: .bottom, relatedBy: .equal, toItem: parentView, attribute: .bottom, multiplier: 1, constant: -10));
parentView.addSubview(progressView);

CRDropdownAlert.show(animationType: .Spring(bounce: 0.5, speed: 0.5), view: parentView, backgroundColor: .black, duration: 3);

CRDropdownalert uses autolayout to determine sizing. When you pass a custom view to show(), the view will be centered horizontally and given some padding around the edges. You will probably need to set progressView.translatesAutoresizingMaskIntoConstraints to false. translatesAutoresizingMaskIntoConstraints will automatically be set to false for you on the customView.

You can also pass a specific window from which the dropdown should be launched.

Support

Feel free to open an issue or issue a PR! Check out the contribution guide for more info.

Installation

CRDropdownAlert is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CRDropdownAlert"

Author

Charles Reitz, cgreitz@gmail.com.

License

CRDropdownAlert is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.