Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker Views #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 102 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
20 changes: 17 additions & 3 deletions Library/PMAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -127,7 +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: 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
Expand Down
26 changes: 19 additions & 7 deletions Library/PMAlertController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PMAlertController" customModule="PMAlertController" customModuleProvider="target">
<connections>
<outlet property="additionalContentView" destination="zHM-CG-3YR" id="KBR-In-bey"/>
<outlet property="additionalContentViewHeightConstraint" destination="Euq-re-Pia" id="niY-RF-VHM"/>
<outlet property="alertActionStackView" destination="WJc-5g-auJ" id="6ho-4f-C1R"/>
<outlet property="alertDescription" destination="BaL-rf-G7t" id="oA9-n7-8tS"/>
<outlet property="alertImage" destination="Rwc-nf-sc4" id="9c2-Rv-Z2W"/>
Expand All @@ -40,7 +42,7 @@
<color key="backgroundColor" red="0.3333333432674408" green="0.3333333432674408" blue="0.3333333432674408" alpha="0.14999999999999999" colorSpace="custom" customColorSpace="sRGB"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dEl-s8-6vU">
<rect key="frame" x="9" y="174.5" width="357" height="318.5"/>
<rect key="frame" x="9" y="175" width="357" height="318"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jTz-eN-yAz" userLabel="Header View">
<rect key="frame" x="0.0" y="8" width="357" height="180"/>
Expand All @@ -59,23 +61,23 @@
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="LMB-jY-4In">
<rect key="frame" x="8" y="198" width="341" height="52.5"/>
<rect key="frame" x="8" y="198" width="341" height="52"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="boW-P6-B3N">
<rect key="frame" x="0.0" y="0.0" width="341" height="23.5"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="21" id="KOt-Js-u7B"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" id="KOt-Js-u7B"/>
</constraints>
<fontDescription key="fontDescription" name="Avenir-Roman" family="Avenir" pointSize="17"/>
<color key="textColor" red="0.92941176469999998" green="0.59607843140000005" blue="0.08235294118" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BaL-rf-G7t">
<rect key="frame" x="0.0" y="31.5" width="341" height="21"/>
<rect key="frame" x="0.0" y="31.5" width="341" height="20.5"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="21" id="cg8-6J-yzj"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" id="cg8-6J-yzj"/>
</constraints>
<fontDescription key="fontDescription" name="Avenir-Medium" family="Avenir" pointSize="15"/>
<color key="textColor" red="0.33333333333333331" green="0.33333333333333331" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand All @@ -86,8 +88,15 @@
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="750" id="nMw-wm-Auu"/>
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="zHM-CG-3YR">
<rect key="frame" x="0.0" y="250" width="357" height="8"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="8" id="Euq-re-Pia"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="WJc-5g-auJ">
<rect key="frame" x="0.0" y="258.5" width="357" height="60"/>
<rect key="frame" x="0.0" y="258" width="357" height="60"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="sZH-1X-biu"/>
</constraints>
Expand All @@ -98,15 +107,18 @@
<constraint firstAttribute="width" constant="357" id="2KX-8C-U18"/>
<constraint firstItem="jTz-eN-yAz" firstAttribute="top" secondItem="dEl-s8-6vU" secondAttribute="top" constant="8" id="AT5-Y6-bpb"/>
<constraint firstAttribute="trailing" secondItem="jTz-eN-yAz" secondAttribute="trailing" id="Ddd-hz-T8q"/>
<constraint firstItem="zHM-CG-3YR" firstAttribute="leading" secondItem="dEl-s8-6vU" secondAttribute="leading" id="G2a-co-edE"/>
<constraint firstItem="LMB-jY-4In" firstAttribute="leading" secondItem="dEl-s8-6vU" secondAttribute="leading" constant="8" id="JoG-bm-Y31"/>
<constraint firstAttribute="bottom" secondItem="WJc-5g-auJ" secondAttribute="bottom" id="P7Y-tt-2D9"/>
<constraint firstAttribute="trailing" secondItem="zHM-CG-3YR" secondAttribute="trailing" id="Pwy-9P-a8k"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="100" id="PzO-yc-cQ1"/>
<constraint firstItem="WJc-5g-auJ" firstAttribute="leading" secondItem="dEl-s8-6vU" secondAttribute="leading" id="Qvh-W5-xGk"/>
<constraint firstItem="jTz-eN-yAz" firstAttribute="leading" secondItem="dEl-s8-6vU" secondAttribute="leading" id="Xmp-HN-MqT"/>
<constraint firstAttribute="trailing" secondItem="WJc-5g-auJ" secondAttribute="trailing" id="bPd-4c-qNR"/>
<constraint firstItem="LMB-jY-4In" firstAttribute="top" secondItem="jTz-eN-yAz" secondAttribute="bottom" constant="10" id="cZ2-BF-gBn"/>
<constraint firstAttribute="trailing" secondItem="LMB-jY-4In" secondAttribute="trailing" constant="8" id="faR-Xx-08y"/>
<constraint firstItem="WJc-5g-auJ" firstAttribute="top" secondItem="LMB-jY-4In" secondAttribute="bottom" constant="8" id="rQm-Go-qos"/>
<constraint firstItem="zHM-CG-3YR" firstAttribute="top" secondItem="LMB-jY-4In" secondAttribute="bottom" id="nvc-mP-PTn"/>
<constraint firstItem="WJc-5g-auJ" firstAttribute="top" secondItem="zHM-CG-3YR" secondAttribute="bottom" id="oBv-io-jAz"/>
</constraints>
</view>
</subviews>
Expand Down
15 changes: 15 additions & 0 deletions PMAlertControllerSample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,27 @@
<action selector="showAlertWithTextEntry:" destination="BYZ-38-t0r" eventType="touchUpInside" id="MWL-bK-Dc4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bWh-3D-Kdf">
<rect key="frame" x="87" y="447" width="200" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="Cnh-MU-PC6"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="mDu-cC-g23"/>
</constraints>
<state key="normal" title="Show Alert with PickerView">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAlertWithPickerView:" destination="BYZ-38-t0r" eventType="touchUpInside" id="AY6-tO-SXx"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="aCJ-yh-itC" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="5pH-xQ-WnV"/>
<constraint firstItem="bWh-3D-Kdf" firstAttribute="top" secondItem="BoA-fU-ZBo" secondAttribute="bottom" constant="8" id="6iS-hK-5sW"/>
<constraint firstItem="9Tf-BW-og0" firstAttribute="top" secondItem="3jJ-qd-rp2" secondAttribute="bottom" constant="8" id="8Pr-Pu-5hK"/>
<constraint firstItem="3jJ-qd-rp2" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="15" id="9fd-Tk-8mu"/>
<constraint firstItem="bWh-3D-Kdf" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Ede-0x-KKu"/>
<constraint firstItem="3jJ-qd-rp2" firstAttribute="top" secondItem="4HV-8v-2tv" secondAttribute="bottom" constant="8" id="GlX-Ff-iqn"/>
<constraint firstItem="BoA-fU-ZBo" firstAttribute="centerX" secondItem="aCJ-yh-itC" secondAttribute="centerX" id="OIZ-3n-yeZ"/>
<constraint firstItem="9Tf-BW-og0" firstAttribute="centerX" secondItem="WaF-QJ-Xl8" secondAttribute="centerX" id="h6x-7g-Wc3"/>
Expand Down
41 changes: 41 additions & 0 deletions PMAlertControllerSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}