Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 3906b9f

Browse files
committedJan 24, 2017
check for menu button
1 parent a9a5f33 commit 3906b9f

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
 

‎.DS_Store

0 Bytes
Binary file not shown.

‎SideMenuController.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SideMenuController'
3-
s.version = '0.2.3'
3+
s.version = '0.2.4'
44
s.license = 'MIT'
55
s.summary = 'Fully customisable and easy to use side menu controller written in Swift.'
66
s.description = 'SideMenuController is a custom container view controller written in Swift which will display the main content within a center panel and the secondary content (option menu, navigation menu, etc.) within a side panel when triggered. The side panel can be displayed either on the left or on the right side, under or over the center panel.'

‎Source/UIKitExtensions.swift

+25-11
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,37 @@ public extension UINavigationController {
4848
button.setImage(image, for: .normal)
4949
button.addTarget(sideMenuController, action: #selector(SideMenuController.toggle), for: UIControlEvents.touchUpInside)
5050

51+
if SideMenuController.preferences.drawing.sidePanelPosition.isPositionedLeft {
52+
let newItems = computeNewItems(sideMenuController: sideMenuController, button: button, controller: self.topViewController, positionLeft: true)
53+
self.topViewController?.navigationItem.leftBarButtonItems = newItems
54+
} else {
55+
let newItems = computeNewItems(sideMenuController: sideMenuController, button: button, controller: self.topViewController, positionLeft: false)
56+
self.topViewController?.navigationItem.rightBarButtonItems = newItems
57+
}
58+
59+
completion?(button)
60+
}
61+
62+
private func computeNewItems(sideMenuController: SideMenuController, button: UIButton, controller: UIViewController?, positionLeft: Bool) -> [UIBarButtonItem] {
63+
64+
var items: [UIBarButtonItem] = (positionLeft ? self.topViewController?.navigationItem.leftBarButtonItems :
65+
self.topViewController?.navigationItem.rightBarButtonItems) ?? []
66+
67+
for item in items {
68+
if let button = item.customView as? UIButton,
69+
button.allTargets.contains(sideMenuController) {
70+
return items
71+
}
72+
}
73+
5174
let item:UIBarButtonItem = UIBarButtonItem()
5275
item.customView = button
5376

5477
let spacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
5578
spacer.width = -10
5679

57-
if SideMenuController.preferences.drawing.sidePanelPosition.isPositionedLeft {
58-
var items = self.topViewController?.navigationItem.leftBarButtonItems ?? []
59-
items.append(contentsOf: [spacer, item])
60-
self.topViewController?.navigationItem.leftBarButtonItems = items
61-
} else {
62-
var items = self.topViewController?.navigationItem.rightBarButtonItems ?? []
63-
items.append(contentsOf: [spacer, item])
64-
self.topViewController?.navigationItem.rightBarButtonItems = [spacer, item]
65-
}
66-
67-
completion?(button)
80+
items.append(contentsOf: positionLeft ? [spacer, item] : [item, spacer])
81+
return items
6882
}
6983
}
7084

0 commit comments

Comments
 (0)
This repository has been archived.