Skip to content

Commit

Permalink
Fix #22, use customView of UIBarButtonItem instead
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Apr 6, 2019
1 parent 0e616fd commit cecaea9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
18 changes: 5 additions & 13 deletions Example/Example/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="nUI-XQ-2oW">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="nUI-XQ-2oW">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.47"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -663,17 +663,8 @@
</connections>
</tableView>
<navigationItem key="navigationItem" title="PopMenu" id="LKE-n9-Moy">
<barButtonItem key="leftBarButtonItem" title="Sign In" style="done" id="Rkb-a5-NV5">
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<action selector="topLeftButtonDidTap:" destination="GCo-K4-qJH" id="6OO-b6-lkw"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" image="Settings_Icon" style="done" id="NEE-IJ-m0H">
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="topRightButtonDidTap:" destination="GCo-K4-qJH" id="e5p-UV-CEP"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
Expand Down Expand Up @@ -715,7 +706,8 @@
</scene>
</scenes>
<resources>
<image name="PopMenu_Logo" width="1500" height="1500"/>
<image name="Settings_Icon" width="17.280000686645508" height="20.399999618530273"/>
<image name="PopMenu_Logo" width="750" height="750"/>
<image name="Settings_Icon" width="36" height="42.5"/>
</resources>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</document>
13 changes: 9 additions & 4 deletions Example/Example/View Controllers/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ class RootViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

let rightButton = UIButton(type: .custom)
rightButton.setImage(#imageLiteral(resourceName: "Settings_Icon"), for: .normal)
rightButton.addTarget(self, action: #selector(topRightButtonDidTap), for: .touchUpInside)

navigationItem.setRightBarButton(UIBarButtonItem(customView: rightButton), animated: true)
}

/// Top left bar button tapped
@IBAction func topLeftButtonDidTap(_ sender: UIBarButtonItem) {
@objc func topLeftButtonDidTap(_ sender: UIBarButtonItem) {
if shouldUseManager {
showMenuWithManager(for: sender)
} else {
Expand All @@ -42,7 +47,7 @@ class RootViewController: UITableViewController {
}

/// Top right bar button tapped
@IBAction func topRightButtonDidTap(_ sender: UIBarButtonItem) {
@objc func topRightButtonDidTap(_ sender: UIButton) {
if shouldUseManager {
showMenuWithManager(for: sender)
} else {
Expand All @@ -53,7 +58,7 @@ class RootViewController: UITableViewController {
/// This shows how to use PopMenu the old fashion way
/// Manually init the controller with actions array
/// Customize whatever you want and present here
fileprivate func showMenuManually(for barButtonItem: UIBarButtonItem) {
fileprivate func showMenuManually(for barButtonItem: AnyObject) {
// Create menu controller with actions
let controller = PopMenuViewController(sourceView: barButtonItem, actions: [
PopMenuDefaultAction(title: "Click me to", image: #imageLiteral(resourceName: "Plus"), color: .yellow),
Expand All @@ -77,7 +82,7 @@ class RootViewController: UITableViewController {
}

/// This shows how to use PopMenu with PopMenuManager
fileprivate func showMenuWithManager(for barButtonItem: UIBarButtonItem) {
fileprivate func showMenuWithManager(for barButtonItem: AnyObject) {
// Get manager instance
let manager = PopMenuManager.default
// Set actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final public class PopMenuViewController: UIViewController {

// Check if UIBarButtonItem
if let sourceBarButtonItem = sourceView as? UIBarButtonItem {
if let buttonView = sourceBarButtonItem.value(forKey: "view") as? UIView {
if let buttonView = sourceBarButtonItem.customView {
return buttonView
}
}
Expand Down

0 comments on commit cecaea9

Please sign in to comment.