如何使用Swift通过编程将UINavigation Bar Button设置为特定图像?

最佳答案

       let rightButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom)
       rightButton.frame = CGRectMake(0, 0, 40, 40) ;
       rightButton.setImage(UIImage(named:"ImageName.png"), forState: UIControlState.Normal)
       rightButton.addTarget(self, action: "rightNavButtonClick:", forControlEvents: UIControlEvents.TouchUpInside)

       var rightBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: rightButton)

       self.navigationItem.setLeftBarButtonItem(rightBarButtonItem, animated: false);

试试这个,这应该工作!!

关于ios - 以编程方式设置UINavigation栏按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29070912/

10-10 15:01