Code Monkey home page Code Monkey logo

pmalertcontroller's Introduction

Icon

Language GitHub license Pod version Carthage Compatible

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable alert that you can use in your iOS app. Enjoy!

Icon

Features


  • Header View
  • Header Image (Optional)
  • Title
  • Description message
  • Customizations: fonts, colors, dimensions & more
  • 1, 2 buttons (horizontally) or 3+ buttons (vertically)
  • Closure when a button is pressed
  • Text Fields support
  • Similar implementation to UIAlertController
  • Cocoapods
  • Carthage
  • Animation with UIKit Dynamics
  • Objective-C compatibility
  • Swift 4, Swift 4.2 & Swift 5 support
  • Swift Package Manager

Requirements


  • iOS 9.0+
  • Xcode 10+

CocoaPods


CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'PMAlertController'

Then, run the following command:

$ pod install

Carthage


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "pmusolino/PMAlertController"

Run carthage update to build the framework and drag the built PMAlertController.framework into your Xcode project.

Manually


  1. Download and drop /Library folder in your project.
  2. Congratulations!

Usage


The usage is very similar to UIAlertController. PMAlertController has two styles: Alert & Walkthrough.

Alert Style: with this style, the alert has the width of 270 points, like Apple's UIAlertController.

Walkthrough Style: with walkthrough, the alert has the width of the screen minus 18 points from the left and the right bounds. This mode is intended to be used before authorization requests like the ones for location, push notifications and more.

Show a simple alert with two buttons and one textfield

//This code works with Swift 5

let alertVC = PMAlertController(title: "A Title", description: "My Description", image: UIImage(named: "img.png"), style: .alert)

alertVC.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: { () -> Void in
            print("Capture action Cancel")
        }))

alertVC.addAction(PMAlertAction(title: "OK", style: .default, action: { () in
            print("Capture action OK")
        }))

alertVC.addTextField { (textField) in
            textField?.placeholder = "Location..."
        }

self.present(alertVC, animated: true, completion: nil)

Swift compatibility

Third Party Bindings

React Native

You may now use this library with React Native via the module here

Contributing

  • If you need help or you'd like to ask a general question, open an issue.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Acknowledgements

Made with ❀️ by Paolo Musolino.

Follow me on:

πŸ’Ό Linkedin

πŸ€– Twitter

πŸŒ‡ Instagram

πŸ‘¨πŸΌβ€πŸŽ€ Facebook

MIT License


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

pmalertcontroller's People

Contributors

942v avatar albinekcom avatar andrewsb avatar blog404de avatar gorbat-o avatar jackyoustra avatar josecostamartins avatar klauslanza avatar lfarah avatar macteo avatar owlcoding avatar pasevin avatar pmusolino avatar prscx avatar shaoxinsen avatar themakew avatar vittoriom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pmalertcontroller's Issues

Can't make alert divider disappear

Couldn't make divider invisible with any of these methods, neither change the color :/

action.isDividerHidden = true
alert.alertActionStackView.isDividerHidden = true
alert.alertActionStackView.arrangedSubviews[0].isDividerHidden = true

use use_modular_headers!

For some reason, I am not using use_frameworks!, but use_modular_headers! instead.
Then it comes with error:

Unable to run command 'StripNIB PMAlertController.nib' - this target might include its own product.
Unable to run command 'StripNIB PMAlertController~iphone.nib' - this target might include its own product.
Unable to run command 'StripNIB PMAlertController~ipad.nib' - this target might include its own product.

performSegue as Action and autodismissing [SOLVED]

Hi,
thanks for this nice controller!

If I use lines of code like this:

alertVC.addAction(PMAlertAction(title: "Only selected supporters.", style: .cancel, action: { () in
            self.performSegue(withIdentifier: "pickA", sender: self)
        }))

The controller pops up and in less then 1 second is dismissing.
Is there a way to avoid this behavior?
Thank you

Michele

Is there a way to prevent the popup to close ?

Hello,

I am building a popup to login in my app, is there a way to prevent the popup to close, in order to tell the user that le credentials are wrong without showing another login popup ?

Obtaining the Textfield value ?

I've implemented the pmalertcontroller with textfield
How could I get the value of the text input by the user ?

Thanks for gr8 library btw πŸ‘

Alert disappear

I think that I found a little bug

If You Call two alert in sequence:

First alert->ok call->second alert

the second alert disappear immediately and block the app with the only maskbackground visible.

If you delay the second alert call this don't happen.

Hope that my explanation is clear.

Not presenting nested Alerts

When presenting the alert view controller, if it is dismissed, and showed again it does not work. Below an example of the code.

let alertController = PMAlertController(title: "Register Sensor", description: String(format: "Please enter the activation code and owner's email of the %@ sensor", arguments: [serialNumber]), image: nil, style: .alert)
        
        alertController.addTextField({ (textField) -> Void in
            textField?.placeholder = "Activation Code"
            textField?.textAlignment = .center
            
        })
        
        alertController.addTextField({ (textField) -> Void in
            textField?.placeholder = "Owner's Email"
            textField?.keyboardType = .emailAddress
            textField?.textAlignment = .center
        })

        alertController.addAction(PMAlertAction(title: "Save", style: .default, action: {
            () -> Void in
            let activationCode = alertController.textFields[0] as UITextField
            let ownerEmail = alertController.textFields[1] as UITextField

            if let code = activationCode.text, let email = ownerEmail.text, code != "", email != "" {
                self.activateSensor(serialNumber: serialNumber, code: code, owner: email, returnCompletion: {
                    (success, object) -> Void in
                    if success {
                        self.getSensors(true)
                    } else {
                        let error = object as? String
                        AlertView.alert(view: self, "Error", message: error ?? "", completion: {
                            (alert) -> Void in
                            self.present(alertController, animated: true, completion: nil)
                        })
                    }
                });
            } else {
                AlertView.alert(view: self, "Error", message: "Please input both activation code and owner's email", completion: {
                    (alert) -> Void in
                    self.present(alertController, animated: true, completion: nil)
                })
            }
        }))
        
        alertController.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: nil))

        self.present(alertController, animated: true, completion: nil)

Progress Bar

Hi Codeido and thanks for your work!

There is a way to add a progress bar to the header view?

Cannot cutomize colors

let alertController = PMAlertController(title: titleText, description: bodyText, image: image, style: .alert) alertController.gravityDismissAnimation = false alertController.alertTitle.tintColor = alertTitleColor alertController.alertDescription.tintColor = alertContentColor

When presented it shows the default colors

Add spinner or rotating images

It would be cool if the alertcontroller had the ability to rotate images or a native spinner option to offer feedback on lengthy tasks,
In the meanwhile I'll try to make my own with QuartzCore and add it as a pull request

Add header view instead image

A UIView is more flexible for show dynamic information besides the title and text.
The height of header view could be flexible.

Thanks for the great library!

Image not centered

Hi, I am experienced an issue.

Now when i load the view the image is to the right not centered as before, the text is correct but not the imagen, what could be wrong?.

thanks

Send notification on alert dismiss

I use PMAlertController in my code but have my own alert queue manager for handling an alert queue, I need to get notified whenever an alert is dismissed. Can you guys add the following code to the viewDidDisappear in the PMAlertController?

NotificationCenter.default.post(name: NSNotification.Name.init("PMAlertDismissed"), object: nil)

Thanks

Cannot scroll

If the alert text cannot fit on the screen the text cannot be scrolled - UIAlertController in contrast supports scrolling by default. What's worse is that the PMAlertController places the "cancel" action off the screen so a user cannot then cancel the alert. The App is effectively blocked from user interaction.

Being able to handle an alert that wont fit completely on screen is important. With devices with different configurations (e.g. screen sizes, portrait, landscape) and dynamic type sizes (i.e. through the settings App a user can increase the text size) its easy to imagine some alerts not fitting a screen.

Otherwise a great library thanks!

Error like Required Xcode 8.0 in Version 1.1.0

I have install PMAlertController in version 1.1.0 in Xcode 7.3 and Deployment target is 9.0 but the issue is something like this :
"This Version does not support documents save in the Xcode 8 format. Open this document with Xcode 8.0 or later."

Use of unresolved identifier 'PMAlertController'

I dragged the /Library folder to the Project Navigation.

Then added this code:

   let alertVC = PMAlertController(title: "A Title", description: "My Description", image: UIImage(named: "img.png"), style: .Alert)

    alertVC.addAction(PMAlertAction(title: "Cancel", style: .Cancel, action: { () -> Void in
        print("Capture action Cancel")
    }))

    alertVC.addAction(PMAlertAction(title: "OK", style: .Default, action: { () in
        print("Capture action OK")
    }))

    self.presentViewController(alertVC, animated: true, completion: nil)

to my ViewController.

However, I get this error:

Use of unresolved identifier 'PMAlertController'

Blackscreen when goes back to alert controller using tab bar ?

I have 3 tab bar items with 3 different view controller.
And I use PMAlertController for the first tab item, it works great but whenever I select another tab item and go back to the first one it gives black screen.

I think it may relate to super views and order of views .

Thanks in advance for the great library.

screen shot 2016-12-12 at 4 08 32 pm

screen shot 2016-12-12 at 4 08 47 pm

screen shot 2016-12-12 at 4 08 40 pm

Manual Installation

CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

Swift4

When will be released a version with Swift4?

Feature request :)

Hi

Can you implement "tap away" feature i.e. if the user taps outside of the PMAlert then to dismiss the Alert window.

Thanks in advance !

Changing background color of an alert

Hi!
I'm trying to change the background color of the alert - can i achieve this with the property "alertMaskBackground"? If so... then it doesn't work - or maybe I don't know how to use it. Can You post some example?

Thanks for the great lib!

Swift 3 Support is missing ?

Hi

I love the library but I don't think it has Swift 3 support as Xcode 8 is telling me that I need to do a lot of changes.

for example:
//MARK: - Customizations
@objc private func setShadowAlertView(){
alertView.layer.masksToBounds = false
alertView.layer.shadowOffset = CGMake(0,0) and should be CGSize(width: 0, height: 0)
alertView.layer.shadowRadius = 8
alertView.layer.shadowOpacity = 0.3
}

What I'm missing ?

Adding extra PMAlertActionStyle

I wanted to use PMAlertAction to imitate UIAlertController, with one difference, that is the ability to show an image above the title. However, I ran into multiple problems when trying to subclass.

PMAlertAction is marked as an open class signing that it should be welcoming to subclassing, but the problem is for example, PMAlertActionStyle is limited to 2 cases, default and cancel but I want to imitate the behaviour of the standard UIAlertController which means I also need destructive.
Even if I wanted to replace PMAlertActionStyle with my own enum, I couldn't since actionStyle is a must have for initialisation.

In addition addSeperator and tapped are internal, so if I don't want to re-write them, I must use the convenience initialiser, which again takes a PMAlertActionStyle and is also extremely "Opinionated" about the design. I wonder what other people do? since I see no choice but forking it and replacing the enum with my own.

It also seems to only be used in 2 places, the init to determine the titleColor and in the animateDismissWithGravity.

I would suggest PMAlertActionStyleType should be a protocol with a var titleColor and var animationStyle. PMAlertActionStyle can confirm to it, maintaining backwards compatibility. While letting other people extend it as needed, as expected from a UI framework.

I am of course aware that I can just crate a PMAlertAction, ignore the PMAlertActionStyle, change whatever I need in it and then return it, but it seems a little weird to do. Maybe it would make more sense if the PMAlertActionStyle had followed UIAlertController and had destructive with a default implementation the looked exactly like UIAlertController, so that a person could use a PMAlertController as plug and play replacement for for UIAlertController. However, as it stands with the yellow title and pinkish red button, it only fits into very specific designs and forces any user to customise it.

Otherwise though, I think it's really great, and a much needed framework, with UIAlertController being so rigid.

Change disappear animation to fade out

Hi,

I love this project however the disappearing animation does not suit my app. I need to change it to something like a fade out (or something else really). I could'n find any way to achieve this. Please help (Some example code would be appreciated)

change the style

Is it possible to customize the font size, and colours?

thanks.

Completion on dismiss did not called

Hi this is an awesome library. Im using it since swift 3 for almost my whole project.
Now im using swift 4 version and run into some trouble.
alertVC.dismiss(animated: false, completion: { () in self.dismiss(animated: true, completion: nil) })
In swift 3 version, the completion block run well. However, after upgrade to swift 4, the completion block did not called. Please help me :D

How to show buttons horizontally?

Hey!

I'm trying to setup the buttons in a horizontal manner. Since I've 2 buttons. But I couldn't make them horizontally aligned. Any suggestions?

extension FavoritesViewController {
    func showAddUser() {
        let alertVC = PMAlertController(title: "Add friend", description: "Please write down your friends username", image: nil, style: .alert)
        
        alertVC.addTextField { (textField) in
            textField?.placeholder = "Username..."
            textField?.autocorrectionType = .no
            textField?.autocapitalizationType = .none
        }
        
        alertVC.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: { () in
            
        }))
        
        alertVC.addAction(PMAlertAction(title: "Add", style: .default, action: { () in
            
        }))

        self.present(alertVC, animated: true, completion: nil)
    }
}

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.