以编程方式设置UINavigationBar按钮

时间:2015-03-16 06:40:50

标签: ios swift uinavigationcontroller

如何使用Swift以编程方式将导航栏按钮设置为特定图像?enter image description here

1 个答案:

答案 0 :(得分:1)

       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);

试试这个应该可行!!