Closed ha-hamed closed 7 years ago
I'll take a look at your issue tomorrow. I'll commit a fix or suggest a workaround.
I came to a solution/workaround with the following code in my implementation:
func prepareNavigationBarMenuTitleView() -> String {
// Both title label and image view are fixed horizontally inside title
// view, UIKit is responsible to center title view in the navigation bar.
// We want to ensure the space between title and image remains constant,
// even when title view is moved to remain centered (but never resized).
titleView = DropDownTitleView(frame: CGRect(x: 0, y: 0, width: 280, height: 40))
titleView.addTarget(self,
action: #selector(DocumentViewController.willToggleNavigationBarMenu(_:)),
for: .touchUpInside)
titleView.addTarget(self,
action: #selector(DocumentViewController.didToggleNavigationBarMenu(_:)),
for: .valueChanged)
titleView.titleLabel.textAlignment = .left
titleView.titleLabel.textColor = UIColor.black
// changes I had to make
titleView.titleLabel.numberOfLines = 2 titleView.frame = CGRect(x: 0, y: 0, width: 280, height: 40) titleView.titleLabel.frame = CGRect(x: 0, y: 0, width: 280, height: 40) titleView.titleLabel.adjustsFontSizeToFitWidth = true
// Had to change the titleView.title to titleView.titleLable.text
titleView.titleLabel.text = currentNode.title
navigationItem.titleView = titleView
return titleView.title!
}
Thanks for the detailed workaround explanation.
I committed a fix that should solve your issue without any workarounds. Let me know if this works for you.
DropDownTitleView
is now automatically resized to match the space available in the navigation bar. This takes in account left and right items. Finally DropDownTitleView.layoutSubviews()
now takes care to center the title and arrow icon properly. If the title is too long, it's also shrunk down and cut automatically according to the ellipsis rule set on DropDownTitleView.titleLabel
.
As a side effect, you don't need to pass a frame when initializing DropDownMenuView
anymore.
@qmathe I tried the commit version, but still did not work for me entirely. It would display the title correctly if it's too long but if I choose a title from the drop down menu it would break it and not present it correctly. So unfortunately i had to revert back to the workaround that I commented above.
I tried to reproduce the issue you describe with DropDownMenuExample, but I couldn't. I added a left and right item in the navigation bar and I also used very long titles for both "Large" and "Small". However switching between the two titles with the menu appears to work fine. Rotating to Landscape seems to behave correctly too.
If you have any other details that can help me to better understand your issue, let me know. Could you also try to reproduce your app issue by changing DropDownMenuExample code? If you manage to do so, please send me the diff.
I am using your framework. I have an issue though. My drop down menu title is overlapping with the right bar buttons. How to solve this issue?