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

Fix #22, use customView of UIBarButtonItem instead #27

Merged
merged 1 commit into from
Apr 6, 2019
Merged
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
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 @@ -635,17 +635,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 @@ -681,7 +672,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