Code Monkey home page Code Monkey logo

crdropdownalert's Introduction

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, [email protected].

License

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

crdropdownalert's People

Contributors

creitz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina

crdropdownalert's Issues

Obj-C Sample Code?

I was wondering if there is any Obj-C sample code or setup instructions. I am trying to slowly convert an old project and need to use bits of Swift and Obj-C and can't get the class methods to work in Obj-C

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.