Crie NavBar programaticamente com Button e Title Swift
Eu tento criar uma NavBar, até agora a NavBar não é problema, mas se eu tentar adicionar botões e o título, sou sugado.
Meu NavBar parece
let NameHeight = screenHeight * 0.09
let NameWidth = screenWidth
let navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: NameWidth, height: NameHeight))
self.view.addSubview(navBar)
então eu tento definir meu título NavBar como
navigationBar.topItem.title = "some title"
or
navigationBar.title = "some title"
mas ambos falham.
Além disso, se eu tentar definir um botão
let btnName = UIButton()
btnName.setImage(UIImage(named: "imagename"), forState: .Normal)
btnName.frame = CGRectMake(0, 0, 30, 30)
btnName.addTarget(self, action: Selector("action"), forControlEvents: .TouchUpInside)
//.... Set Right/Left Bar Button item
let rightBarButton = UIBarButtonItem()
rightBarButton.customView = btnName
self.navigationItem.rightBarButtonItem = rightBarButton
isso não me dá um erro, mas o botão simplesmente não é exibido