【发布时间】:2017-07-27 08:10:44
【问题描述】:
我在viewDidLoad 中有以下内容。它设置了一个自定义的rightBarButtonItem(在一个自定义的UINavigationBar 中)。
let button = UIButton()
let attrs = [NSFontAttributeName: UIFont(name: "Montserrat-Light", size: 14)!, NSForegroundColorAttributeName: UIColor.black]
let title = NSAttributedString(string: "Sign In", attributes: attrs)
button.setAttributedTitle(title, for: .normal)
button.addTarget(self, action: #selector(self.pushVcLogin), for: .touchUpInside)
let parentView = UIView(frame: button.bounds)
parentView.addSubview(button)
button.sizeToFit()
parentView.bounds = CGRect(x: 0, y: 0, width: button.bounds.size.width, height: button.bounds.size.height)
self.navItem.rightBarButtonItem = UIBarButtonItem(customView: parentView)
自定义的UIBarButtonItem 看起来应该是这样,但它不可点击。
有什么想法吗?
【问题讨论】:
-
可以分享一下“pushVcLogin”的代码吗?
-
“自定义
UINavigationBar”是什么意思?您是否使用UINavigationController?只是“自定义”的视觉外观,还是您使用的是独立的导航栏? -
对不起,我想通了——整个视图控制器(提示@NicolasMiari 的问题)嵌套在 UINavigationController 中,并且该控制器(无形地)将其 UINavigationBar 叠加在我的整个视图上,包括我的自定义 UINavigationBar。
标签: ios swift uinavigationbar uibarbuttonitem