diff --git a/Library/PMAlertController.swift b/Library/PMAlertController.swift index edd26be..d778572 100755 --- a/Library/PMAlertController.swift +++ b/Library/PMAlertController.swift @@ -21,11 +21,20 @@ import UIKit @IBOutlet weak open var alertViewWidthConstraint: NSLayoutConstraint! @IBOutlet weak open var headerView: UIView! @IBOutlet weak open var headerViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak open var headerViewTopSpaceConstraint: NSLayoutConstraint! @IBOutlet weak open var alertImage: UIImageView! @IBOutlet weak open var alertTitle: UILabel! @IBOutlet weak open var alertDescription: UILabel! + @IBOutlet weak open var alertContentStackViewLeadingConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertContentStackViewTrailingConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertContentStackViewTopConstraint: NSLayoutConstraint! @IBOutlet weak open var alertActionStackView: UIStackView! - @IBOutlet weak open var alertStackViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertActionStackViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertActionStackViewLeadingConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertActionStackViewTrailingConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertActionStackViewTopConstraint: NSLayoutConstraint! + @IBOutlet weak open var alertActionStackViewBottomConstraint: NSLayoutConstraint! + open var ALERT_STACK_VIEW_HEIGHT : CGFloat = UIScreen.main.bounds.height < 568.0 ? 40 : 62 //if iphone 4 the stack_view_height is 40, else 62 var animator : UIDynamicAnimator? @@ -81,11 +90,11 @@ import UIKit alertActionStackView.addArrangedSubview(alertAction) if alertActionStackView.arrangedSubviews.count > 2 || hasTextFieldAdded(){ - alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count) + alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count) alertActionStackView.axis = .vertical } else{ - alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT + alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT alertActionStackView.axis = .horizontal } @@ -118,7 +127,7 @@ import UIKit } func _addTextField(_ textField: UITextField){ alertActionStackView.addArrangedSubview(textField) - alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count) + alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count) alertActionStackView.axis = .vertical textFields.append(textField) } diff --git a/Library/PMAlertController.xib b/Library/PMAlertController.xib index 8483da7..0c20406 100644 --- a/Library/PMAlertController.xib +++ b/Library/PMAlertController.xib @@ -1,32 +1,34 @@ - + - + - - - Avenir-Medium - Avenir-Roman - - + + + + + + + + - + @@ -58,7 +60,7 @@ - + @@ -97,7 +110,9 @@ + + diff --git a/PMAlertControllerSample/ViewController.swift b/PMAlertControllerSample/ViewController.swift index 484ac12..8332812 100755 --- a/PMAlertControllerSample/ViewController.swift +++ b/PMAlertControllerSample/ViewController.swift @@ -104,4 +104,30 @@ class ViewController: UIViewController { self.present(alertVC, animated: true, completion: nil) } + + @IBAction func showWalkthroughWithCustomPaddings(_ sender: AnyObject) { + let alertVC = PMAlertController(title: "Locate your device", description: "Enables access to your location: discover what you can do when you're traveling and what is available near you.", image: UIImage(named: "flag.png"), style: .walkthrough) //Image by freepik.com, taken on flaticon.com + + + alertVC.headerViewTopSpaceConstraint.constant = 20 + alertVC.alertContentStackViewLeadingConstraint.constant = 20 + alertVC.alertContentStackViewTrailingConstraint.constant = 20 + alertVC.alertContentStackViewTopConstraint.constant = 20 + alertVC.alertActionStackViewLeadingConstraint.constant = 20 + alertVC.alertActionStackViewTrailingConstraint.constant = 20 + alertVC.alertActionStackViewTopConstraint.constant = 20 + alertVC.alertActionStackViewBottomConstraint.constant = 20 + alertVC.view.layoutIfNeeded() + + alertVC.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: { () -> Void in + print("Cancel") + })) + + alertVC.addAction(PMAlertAction(title: "Allow", style: .default, action: { () in + print("Allow") + })) + + self.present(alertVC, animated: true, completion: nil) + } + }