在UINavigationController中为viewController添加一个多按钮, 我只是这一行:
self.navigationItem.rightBarButtonItems = [my button]
但我没有成功将其添加到UINavigationController的视图中:
//create new navigation item. and add it to the nvigation bar
customNavigationItem = UINavigationItem()
/* now we need to add the menu + search to the navigation item */
//create search button
let searchButton = UIButton();
searchButton.frame = CGRectMake(0, 0, 50.0, 50.0);
searchButton.backgroundColor = UIColor.redColor();
searchButton.titleLabel!.font = UIFont.iconmoonFont(14.0)
searchButton.titleLabel?.textColor = UIColor.whiteColor()
searchButton.titleLabel!.text = IconsConstants.SEARCH;//SEARCH ICON TEXT
searchButton.backgroundColor = UIColor.clearColor();
searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
searchButton.contentVerticalAlignment = UIControlContentVerticalAlignment.Center;
let searchUIbarBtn = UIBarButtonItem.init(customView: searchButton)
//create menu button
let menuButton = UIButton();
menuButton.frame = CGRectMake(0, 0, 40.0, 40.0);
menuButton.titleLabel!.font = UIFont.iconmoonFont(14.0)
menuButton.backgroundColor = UIColor.whiteColor()
menuButton.titleLabel!.text = IconsConstants.MENU;//SEARCH ICON TEXT
menuButton.backgroundColor = UIColor.clearColor();
menuButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
menuButton.contentVerticalAlignment = UIControlContentVerticalAlignment.Center;
let menuUIbarBtn = UIBarButtonItem.init(customView: menuButton)
//add button to NavigationItem
customNavigationItem.rightBarButtonItems = [menuUIbarBtn,searchUIbarBtn];
/* add navigation bar */
navigationBar = UINavigationBar();
navigationBar.frame = CGRectMake(0, statusBarHeight, self.view.frame.size.width, 44);
//navigationBar.translucent = false
navigationBar.barTintColor = UIColor.statusBarColor()
navigationBar.items = [customNavigationItem]
self.view.addSubview(navigationBar)
我无法理解为什么我的酒吧没有任何按钮?