Skip to content

Commit

Permalink
Update demo with UIBarButtonItems functionality teambition#3
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-hirsch committed May 11, 2016
1 parent 565ebe5 commit 64c083a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 9 deletions.
44 changes: 38 additions & 6 deletions DropDown/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E36b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="6vj-VF-JaB">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Vku-BY-Uzo">
<rect key="frame" x="30" y="148" width="540" height="40"/>
<rect key="frame" x="30" y="192" width="540" height="40"/>
<color key="backgroundColor" red="0.83930421270718236" green="0.83930421270718236" blue="0.83930421270718236" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="ZQR-BF-ukN"/>
Expand All @@ -33,12 +33,12 @@
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Focus here to test with keyboard" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="dET-0t-URe">
<rect key="frame" x="30" y="48" width="540" height="30"/>
<rect key="frame" x="30" y="92" width="540" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7rm-SA-osO">
<rect key="frame" x="247" y="98" width="107" height="30"/>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7rm-SA-osO">
<rect key="frame" x="248" y="142" width="106" height="30"/>
<state key="normal" title="Random button">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
Expand All @@ -61,8 +61,22 @@
<outletCollection property="gestureRecognizers" destination="Pgd-VX-BIf" appends="YES" id="Ng7-os-Bjv"/>
</connections>
</view>
<navigationItem key="navigationItem" id="2VY-da-j73">
<barButtonItem key="leftBarButtonItem" title="•••" id="7HL-OV-wFS">
<connections>
<action selector="showLeft:" destination="vXZ-lx-hvc" id="t9i-ZT-eId"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="•••" id="Go8-kG-PuV">
<connections>
<action selector="showRight:" destination="vXZ-lx-hvc" id="fAo-uR-q0b"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="actionButton" destination="Vku-BY-Uzo" id="lne-cw-Km8"/>
<outlet property="leftBarButton" destination="7HL-OV-wFS" id="5Zc-QS-esj"/>
<outlet property="rightBarButton" destination="Go8-kG-PuV" id="wBb-lo-Aeo"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
Expand All @@ -72,6 +86,24 @@
</connections>
</tapGestureRecognizer>
</objects>
<point key="canvasLocation" x="1589" y="681"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="BXm-fh-f0T">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="6vj-VF-JaB" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="nbq-CX-E1j">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="mLv-ak-gFb"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="IYQ-tQ-ioz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="777" y="681"/>
</scene>
</scenes>
Expand Down
62 changes: 59 additions & 3 deletions DropDown/demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,33 @@ import UIKit
class ViewController: UIViewController {

@IBOutlet weak var actionButton: UIButton!
@IBOutlet weak var rightBarButton: UIBarButtonItem!
@IBOutlet weak var leftBarButton: UIBarButtonItem!

let dropDown = DropDown()
let dropDownLeft = DropDown()
let dropDownRight = DropDown()

override func viewDidLoad() {
super.viewDidLoad()

setupDropDown()
setupLeftBarButtonItemDropDown()
setupRightBarButtonItemDropDown()
}

func setupDropDown() {
dropDown.anchorView = actionButton

// Will set a custom with instead of anchor view width
// dropDownLeft.width = 100

// By default, the dropdown will have its origin on the top left corner of its anchor view
// So it will come over the anchor view and hide it completely
// If you want to have the dropdown underneath your anchor view, you can do this:
dropDown.bottomOffset = CGPoint(x: 0, y:actionButton.bounds.height)

// You can also use localizationKeysDataSource instead. Check the docs.
dropDown.dataSource = [
"Car",
"Motorcycle",
Expand All @@ -26,22 +48,48 @@ class ViewController: UIViewController {
"Feet"
]

// Action triggered on selection
dropDown.selectionAction = { [unowned self] (index, item) in
self.actionButton.setTitle(item, forState: .Normal)
}


// Action triggered on dropdown cancelation (hide)
// dropDown.cancelAction = { [unowned self] in
// self.dropDown.selectRowAtIndex(-1)
// // You could for example deselect the selected item
// self.dropDown.deselectRowAtIndexPath(self.dropDown.indexForSelectedRow)
// self.actionButton.setTitle("Canceled", forState: .Normal)
// }

dropDown.anchorView = actionButton
dropDown.bottomOffset = CGPoint(x: 0, y:actionButton.bounds.height)
// Check the different dismiss modes in the docs.
// dropDown.dismissMode = .Automatic

// You can manually select a row if needed
// dropDown.selectRowAtIndex(3)
}

func setupLeftBarButtonItemDropDown() {
dropDownLeft.width = 100 // Important to set or the dropdown will have a 0 width
dropDownLeft.anchorView = leftBarButton
dropDownLeft.dataSource = [
"Menu 1",
"Menu 2",
"Menu 3",
"Menu 4",
"Menu 5",
]
}

func setupRightBarButtonItemDropDown() {
dropDownRight.width = 100 // Important to set or the dropdown will have a 0 width
dropDownRight.anchorView = rightBarButton
dropDownRight.dataSource = [
"Menu 1",
"Menu 2",
"Menu 3",
]
}

@IBAction func showOrDismiss(sender: AnyObject) {
if dropDown.hidden {
dropDown.show()
Expand All @@ -50,6 +98,14 @@ class ViewController: UIViewController {
}
}

@IBAction func showLeft(sender: AnyObject) {
dropDownLeft.show()
}

@IBAction func showRight(sender: AnyObject) {
dropDownRight.show()
}

@IBAction func viewTapped() {
view.endEditing(false)
}
Expand Down

0 comments on commit 64c083a

Please sign in to comment.