Skip to content

JDAlertController is AlertController replica that can significantly enhance your users experiences and set your app apart from the rest of the pack. You don’t need to do much to integrate it.Its build using UIViewControllerTransitioningDelegate and UIPresentationController having four types of UIViewControllerAnimatedTransitioning animations and…

Notifications You must be signed in to change notification settings

jwd-ali/JDAlertController

Repository files navigation

JDAlertController

CI Status CocoaPods Version Carthage Compatible License Platform Swift 5.1

JDAlertController is AlertController replica that can significantly enhance your users’ experiences and set your app apart from the rest of the pack.


You don’t need to do much to integrate it. Its build using UIViewControllerTransitioningDelegate and UIPresentationController having four types of UIViewControllerAnimatedTransitioning animations and many more customisations with different buttons styles and UITextField support as well

Error and Success Animations are build using CABasicAnimation and CAShapeLayer through UIBezierpath. Its fun to play with CoreGraphics.It starts slow and By the end, you’ll be able to create stunning graphics for your apps.



Requirements

  • iOS 11.0+ / Mac OS X 10.9+ / watchOS 2.0+ / tvOS 9.0+
  • Xcode 8.0+

Installation

To integrate JDAlertController into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod 'JDAlertController'

Then, run the following command:

$ pod install

To integrate JDAlertController into your Xcode project using Carthage, specify it in your Cartfile:

github "jwd-ali/JDAlertController"

Prerequisites

  • OSX

Update Package.swift

To integrate JDAlertController in your project, add the proper description to your Package.swift file:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/jwd-ali/JDAlertController.git")
    ],
    targets: [
        .target(
            name: "YOUR_TARGET_NAME",
            dependencies: ["JDAlertController"]
        ),
        ...
    ]
)

Manually

If you prefer not to use a dependency manager, you can integrate JDAlertController into your project manually.

  • Add sources into your project:
    • Drag Sources

Usage

If you are using any dependency manager (pods , carthage , package manager)to integrate JDAlertController. Import JDAlertController first:

import JDAlertController

And for Manuall install you dont need to import anything

  • Init your ring with Alert same as you initialize default UIAlertController:
  let alert = AlertController(icon: UIImage(named: "iconName"),
                                    title: "Can We Help?",
                                    message: "Any questions or feedback? We are here to help you! ",
                                    preferredStyle: .alert)

We can show alert with 4 different styles

public enum PopupStyle {
    case alert
    case actionSheet(offset: Double)
    case topSheet(offset: Double)
    case dragIn
}

Action sheet and top sheet support offset as well if you want to position it some point rather then attaching to bottom or top You can also set the icon size in the initializer like this

let alert = AlertController(icon: UIImage(named: "write"),
                                    title: "Can We Help?",
                                    message: "Any questions or feedback? We are here to help you! ",
                                    preferredStyle: Settings.shared.preferedStyle,
                                    iconSize: 80)

Here you are giving top icon size to 80 points

You can enable touch anywhere outside the alert to dismiss it on

alert.tapToClose = true

If its On user can tap anywhere outside popup to dismiss it.

You can also enable draging and fast drag dismiss by setting the key isDragEnable

alert.isDragEnable = true

You can control the width of the popup using key widthRatio ita ratio of total screen width. its value should be in range 0...1

alert.widthRatio = 0.8

For Animated success or failure you need to set PopupType in inializer like this

public enum PopupType {
    case success
    case error
}

let alert = AlertController(type: .success,
                                    title: "Awaiting your payment!",
                                    message: "Leo Walton will receive \n 62,500.00 PKR ",
                                    preferredStyle: Settings.shared.preferedStyle)

And set the isAnimated property to true if you want Top to bottom animation like unfolding

 alert.isAnimated = true

Adding buttons and TextFields in alert is as simple as adding them in Alert controller

 let homeAction = PopupAction(title: "No, Thanks",
                                     style: .classic(cornerRadius: 5),
                                     propotionalWidth: .margin) {

        }
        
        alert.addAction(homeAction)

Same as AlertController we get closure to do actions while declaring buttons and dismissal of popup is auto so you dont need to dismiss the alert on taping of the button We have different style buttons available to inject into the Action

 public enum Style {

        case `default`
        case bold
        case destructive
        case round
        case classic(cornerRadius: CGFloat)
        case justText
    }

I think they are self explainatory as their name. Also you can have sizes of buttons as well

public enum ButtonWidth {
        case full
        case margin
        case normal
        case custom(ratio: CGFloat)
    }

Where full are full width and you can also have custom width and marginal width as well here is the propotinal width graph

var buttonSize: CGFloat {
            switch propotionalWidth {
            case .full:
                return 1.0
            case .margin:
                return 0.9
            case .normal:
                return 0.75
            case .custom(let width):
                return width
            }
        }

It explain the width of the button

Adding Text fields is also as easy as its native control

 let emailField = AppTextField(with: "User Name or Email")
        let passwordField = AppTextField(with: "Password")
        passwordField.isSecureTextEntry = true

        alert.addTextField(emailField)
        alert.addTextField(passwordField)

And then you can access them like this

  let firstTextField =  alert.textFields.first

Congratulations! You're done.

Contributing

I’d love to have help on this project. For small changes please open a pull request, for larger changes please open an issue first to discuss what you’d like to see.

License

JDAlertController is under MIT. See LICENSE file for more info.

About

JDAlertController is AlertController replica that can significantly enhance your users experiences and set your app apart from the rest of the pack. You don’t need to do much to integrate it.Its build using UIViewControllerTransitioningDelegate and UIPresentationController having four types of UIViewControllerAnimatedTransitioning animations and…

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published