From 9378cdac91cda076141c2d2a7a8ac4a1cfd2f29d Mon Sep 17 00:00:00 2001 From: Salil Date: Tue, 6 Feb 2018 14:03:04 -0500 Subject: [PATCH 1/3] Blank title and subtitle height adjustments --- .gitignore | 105 +++++++++++++++++++++++++++++++++- Library/PMAlertController.xib | 12 ++-- 2 files changed, 108 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index fadc1e6..d5ae421 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,102 @@ -*.xcbkptlist -PMAlertController.xcodeproj/project.xcworkspace/xcuserdata -Carthage/ +##### +# OS X temporary files that should never be committed +.DS_Store +*.swp +*.lock +profile + +##### +# DotEnv files +.env + +#### +# Xcode temporary files that should never be committed +*~.nib + +#### +# Objective-C/Swift specific +*.hmap +*.ipa + +#### +# Xcode build files +DerivedData/ +build/ +Builds/ + +##### +# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +#### +# Xcode 4 +xcuserdata +!xcschemes +# Xcode 4 +*.moved-aside + +#### +# XCode 4 workspaces - more detailed +!xcshareddata +!default.xcworkspace +*.xcworkspacedata + + +#### +# Xcode 5 +*.xccheckout +*.xcuserstate + +#### +# Xcode 7 +*.xcscmblueprint + +#### +# AppCode +.idea/ + +#### +# Other Xcode files +profile +*.hmap +*.ipa + +#### +# CocoaPods +Pods/ +!Podfile +!Podfile.lock + +#### +# Carthage +Carthage/Build.rbenv-vars +!Cartfile +!Cartfile.private +!Cartfile.resolved + +#### +# Fastlane +# Temporary profiling data +/fastlane/report.xml +# Deliver temporary error output +/fastlane/Error*.png +# Deliver temporary preview output +/fastlane/Preview.html +# Snapshot generated screenshots +/fastlane/screenshots/*/*-portrait.png +/fastlane/screenshots/*/*-landscape.png +/fastlane/screenshots/screenshots.html +# Frameit generated screenshots +/fastlane/screenshots/*/*-portrait_framed.png +/fastlane/screenshots/*/*-landscape_framed.png + +#### +# rbenv +.rbenv-vars \ No newline at end of file diff --git a/Library/PMAlertController.xib b/Library/PMAlertController.xib index 8483da7..258e4f1 100644 --- a/Library/PMAlertController.xib +++ b/Library/PMAlertController.xib @@ -40,7 +40,7 @@ - + @@ -59,23 +59,23 @@ - + - + From 7aaabe3bb062919a08bab65a09721313480abfc5 Mon Sep 17 00:00:00 2001 From: Salil Date: Tue, 6 Feb 2018 15:25:37 -0500 Subject: [PATCH 2/3] You can now add picker views in the alert controller --- Library/PMAlertController.swift | 19 ++++++++- Library/PMAlertController.xib | 14 ++++++- .../Base.lproj/Main.storyboard | 15 +++++++ PMAlertControllerSample/ViewController.swift | 41 +++++++++++++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/Library/PMAlertController.swift b/Library/PMAlertController.swift index a6e90be..c213b10 100755 --- a/Library/PMAlertController.swift +++ b/Library/PMAlertController.swift @@ -14,8 +14,8 @@ import UIKit } @objc open class PMAlertController: UIViewController { - - // MARK: Properties + + // MARK: Properties @IBOutlet weak open var alertMaskBackground: UIImageView! @IBOutlet weak open var alertView: UIView! @IBOutlet weak open var alertViewWidthConstraint: NSLayoutConstraint! @@ -24,6 +24,8 @@ import UIKit @IBOutlet weak open var alertImage: UIImageView! @IBOutlet weak open var alertTitle: UILabel! @IBOutlet weak open var alertDescription: UILabel! + @IBOutlet weak open var additionalContentView: UIView! + @IBOutlet weak open var additionalContentViewHeightConstraint: NSLayoutConstraint! @IBOutlet weak open var alertActionStackView: UIStackView! @IBOutlet weak open var alertStackViewHeightConstraint: 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 @@ -127,6 +129,19 @@ import UIKit func hasTextFieldAdded () -> Bool{ return textFields.count > 0 } + + //MARK: - Picker View + @objc open func addPickerView(_ pickerView: UIPickerView) { + self.additionalContentView.addSubview(pickerView) + + pickerView.translatesAutoresizingMaskIntoConstraints = false + pickerView.topAnchor.constraint(equalTo: self.additionalContentView.topAnchor, constant: 16).isActive = true + pickerView.leadingAnchor.constraint(equalTo: self.additionalContentView.leadingAnchor, constant: 16).isActive = true + pickerView.trailingAnchor.constraint(equalTo: self.additionalContentView.trailingAnchor, constant: -16).isActive = true + pickerView.bottomAnchor.constraint(equalTo: self.additionalContentView.bottomAnchor).isActive = true + self.additionalContentViewHeightConstraint.constant = pickerView.frame.size.height + } + //MARK: - Customizations @objc fileprivate func setShadowAlertView(){ diff --git a/Library/PMAlertController.xib b/Library/PMAlertController.xib index 258e4f1..fc4ffbb 100644 --- a/Library/PMAlertController.xib +++ b/Library/PMAlertController.xib @@ -17,6 +17,8 @@ + + @@ -86,6 +88,13 @@ + + + + + + + @@ -98,15 +107,18 @@ + + - + + diff --git a/PMAlertControllerSample/Base.lproj/Main.storyboard b/PMAlertControllerSample/Base.lproj/Main.storyboard index cebe167..edb26ea 100644 --- a/PMAlertControllerSample/Base.lproj/Main.storyboard +++ b/PMAlertControllerSample/Base.lproj/Main.storyboard @@ -86,12 +86,27 @@ + + + diff --git a/PMAlertControllerSample/ViewController.swift b/PMAlertControllerSample/ViewController.swift index 61ca0e8..52421dc 100755 --- a/PMAlertControllerSample/ViewController.swift +++ b/PMAlertControllerSample/ViewController.swift @@ -10,6 +10,9 @@ import UIKit import PMAlertController class ViewController: UIViewController { + + var pickerOptionsOne = ["Evil", "Super", "Incredible", "Wonder", "Sliver", "Bacon"] + var pickerOptionsTwo = ["Destroyer", "Man", "Daddy", "Lord", "Girl", "Astronaut"] override func viewDidLoad() { super.viewDidLoad() @@ -105,3 +108,41 @@ class ViewController: UIViewController { self.present(alertVC, animated: true, completion: nil) } } + +extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource { + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 2 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return component == 0 ? pickerOptionsOne.count : pickerOptionsTwo.count + } + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return component == 0 ? pickerOptionsOne[row] : pickerOptionsTwo[row] + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + print (component == 0 ? pickerOptionsOne[row] : pickerOptionsTwo[row]) + } + + @IBAction func showAlertWithPickerView(_ sender: UIButton) { + let alertVC = PMAlertController(title: "Hero Name Maker", description: "Make your very own Superhero!!", image: UIImage(named: "flag.png"), style: .alert) + + let pickerView = UIPickerView(frame: .zero) + pickerView.delegate = self + pickerView.dataSource = self + alertVC.addPickerView(pickerView) + + alertVC.addAction(PMAlertAction(title: "Ok", style: .default)) + + self.present(alertVC, animated: true, completion: nil) + } +} + + + + + + + From d24a0d432ebf5af976655df0e75c0e71b28c167c Mon Sep 17 00:00:00 2001 From: Salil Date: Tue, 6 Feb 2018 16:32:46 -0500 Subject: [PATCH 3/3] PickerView constraints fix --- Library/PMAlertController.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Library/PMAlertController.swift b/Library/PMAlertController.swift index c213b10..a4b4a46 100755 --- a/Library/PMAlertController.swift +++ b/Library/PMAlertController.swift @@ -130,19 +130,18 @@ import UIKit return textFields.count > 0 } - //MARK: - Picker View - @objc open func addPickerView(_ pickerView: UIPickerView) { - self.additionalContentView.addSubview(pickerView) - - pickerView.translatesAutoresizingMaskIntoConstraints = false - pickerView.topAnchor.constraint(equalTo: self.additionalContentView.topAnchor, constant: 16).isActive = true - pickerView.leadingAnchor.constraint(equalTo: self.additionalContentView.leadingAnchor, constant: 16).isActive = true - pickerView.trailingAnchor.constraint(equalTo: self.additionalContentView.trailingAnchor, constant: -16).isActive = true - pickerView.bottomAnchor.constraint(equalTo: self.additionalContentView.bottomAnchor).isActive = true - self.additionalContentViewHeightConstraint.constant = pickerView.frame.size.height - } + //MARK: - Picker View + @objc open func addPickerView(_ pickerView: UIPickerView) { + self.additionalContentView.addSubview(pickerView) + + pickerView.translatesAutoresizingMaskIntoConstraints = false + pickerView.topAnchor.constraint(equalTo: self.additionalContentView.topAnchor, constant: 8).isActive = true + pickerView.leadingAnchor.constraint(equalTo: self.additionalContentView.leadingAnchor, constant: 16).isActive = true + pickerView.trailingAnchor.constraint(equalTo: self.additionalContentView.trailingAnchor, constant: -16).isActive = true + pickerView.bottomAnchor.constraint(equalTo: self.additionalContentView.bottomAnchor, constant: 0).isActive = true + self.additionalContentViewHeightConstraint.constant = pickerView.frame.size.height + } - //MARK: - Customizations @objc fileprivate func setShadowAlertView(){ alertView.layer.masksToBounds = false