Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
check for menu button
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorpatras committed Jan 24, 2017
1 parent a9a5f33 commit 3906b9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion SideMenuController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SideMenuController'
s.version = '0.2.3'
s.version = '0.2.4'
s.license = 'MIT'
s.summary = 'Fully customisable and easy to use side menu controller written in Swift.'
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.'
Expand Down
36 changes: 25 additions & 11 deletions Source/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,37 @@ public extension UINavigationController {
button.setImage(image, for: .normal)
button.addTarget(sideMenuController, action: #selector(SideMenuController.toggle), for: UIControlEvents.touchUpInside)

if SideMenuController.preferences.drawing.sidePanelPosition.isPositionedLeft {
let newItems = computeNewItems(sideMenuController: sideMenuController, button: button, controller: self.topViewController, positionLeft: true)
self.topViewController?.navigationItem.leftBarButtonItems = newItems
} else {
let newItems = computeNewItems(sideMenuController: sideMenuController, button: button, controller: self.topViewController, positionLeft: false)
self.topViewController?.navigationItem.rightBarButtonItems = newItems
}

completion?(button)
}

private func computeNewItems(sideMenuController: SideMenuController, button: UIButton, controller: UIViewController?, positionLeft: Bool) -> [UIBarButtonItem] {

var items: [UIBarButtonItem] = (positionLeft ? self.topViewController?.navigationItem.leftBarButtonItems :
self.topViewController?.navigationItem.rightBarButtonItems) ?? []

for item in items {
if let button = item.customView as? UIButton,
button.allTargets.contains(sideMenuController) {
return items
}
}

let item:UIBarButtonItem = UIBarButtonItem()
item.customView = button

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

if SideMenuController.preferences.drawing.sidePanelPosition.isPositionedLeft {
var items = self.topViewController?.navigationItem.leftBarButtonItems ?? []
items.append(contentsOf: [spacer, item])
self.topViewController?.navigationItem.leftBarButtonItems = items
} else {
var items = self.topViewController?.navigationItem.rightBarButtonItems ?? []
items.append(contentsOf: [spacer, item])
self.topViewController?.navigationItem.rightBarButtonItems = [spacer, item]
}

completion?(button)
items.append(contentsOf: positionLeft ? [spacer, item] : [item, spacer])
return items
}
}

Expand Down

0 comments on commit 3906b9f

Please sign in to comment.