pmusolino / PMAlertController

PMAlertController is a great and customizable alert that can substitute UIAlertController
MIT License
2.53k stars 187 forks source link

Add orientation #21

Closed bmichotte closed 8 years ago

bmichotte commented 8 years ago

Hi there !

Sometimes, the label for your button is too long to be displayed correctly, which results in something like this

capture d ecran 2016-08-01 a 15 27 22

This PR add a new parameter in the init : orientation. This parameter have the type PMAlertControllerOrientation which have the following values : Default (this is the default value) -> The buttons will be show as for now (horizontally if 1 or 2 buttons, vertically if more than 2 buttons) Vertical -> force the buttons to be shown vertically Horizontal -> force the buttons to be shown horizontally

Example:


@IBAction func showVertical2Buttons(sender: AnyObject) {
        let alertVC = PMAlertController(title: "Locate your device", 
             description: "Enables access to you.....", 
             image: UIImage(named: "flag.png"), 
             style: .Alert, 
             orientation: .Vertical)

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

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

which will be displayed like this capture d ecran 2016-08-01 a 15 26 56

pmusolino commented 8 years ago

Hi @bmichotte, thank you for your contribution, but i think that all this implementation is not necessary, because there is the possibility to access to the stackview and change the axis (vertical or horizontal). In this way the popup as a default behavior, but if you want you can change the axis.

Thanks -Paolo

bmichotte commented 8 years ago

Hi @Codeido, my first attempt was to use the stackview directly. There's only one problem with this which is that alertStackViewHeightConstraint is private, so if we want to use your constraint, it's not possible. Could you at least mark this var public ?

pmusolino commented 8 years ago

@bmichotte thanks for the suggestion. I updated the library and now alertStackViewHeightConstraint is public. From now you can use the release 1.0.5.

Thanks -Paolo

bmichotte commented 8 years ago

Thanks @Codeido