如何将未嵌入导航控制器的导航栏添加到视图控制器(实际上是集合视图控制器)?我尝试将导航栏拖动到视图上,但它并不粘滞。这是在Swift中。
尝试将此代码放入您的viewDidLoad
:
let height: CGFloat = 75
let navbar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: height))
navbar.backgroundColor = UIColor.whiteColor()
navbar.delegate = self
let navItem = UINavigationItem()
navItem.title = "Title"
navItem.leftBarButtonItem = UIBarButtonItem(title: "Left Button", style: .Plain, target: self, action: nil)
navItem.rightBarButtonItem = UIBarButtonItem(title: "Right Button", style: .Plain, target: self, action: nil)
navbar.items = [navItem]
view.addSubview(navbar)
collectionView?.frame = CGRect(x: 0, y: height, width: UIScreen.mainScreen().bounds.width, height: (UIScreen.mainScreen().bounds.height - height))
height
当然可以成为您想要的任何东西。UIBarButton
s的动作是您想要的任何功能的选择器。(您也完全不需要按钮)。
编辑:
collectionView
的镜框,使其不会与重叠UINavigationBar
。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句