Swift CustomNavigationController navigationItem不起作用

时间:2017-07-23 10:09:47

标签: ios uinavigationcontroller

AppDelegate

let navigationController = ExampleNavigationController.init(rootViewController: tabBarController)
tabBarController.title = "Modda"
self.window?.rootViewController = navigationController

ExampleNavigationController

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationBar.isTranslucent = false
    self.navigationBar.barTintColor = UIColor.init(red: 250/255.0, green: 250/255.0, blue: 250/255.0, alpha: 0.8)
    self.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.init(red: 44/255.0, green: 49/255.0, blue: 64/255.0, alpha: 1.0), NSFontAttributeName: UIFont.systemFont(ofSize: 16.0)]
    self.navigationBar.tintColor = UIColor.init(red: 44/255.0, green: 49/255.0, blue: 64/255.0, alpha: 1.0)

    self.navigationItem.title = "Modda"

    //Left Item Button
    let button = UIButton.init(type: .custom)
    button.setImage(UIImage.init(named: "menu"), for: UIControlState.normal)
    //button.addTarget(self, action:#selector(SSASideMenu.presentLeftMenuViewController), for: UIControlEvents.touchUpInside)
    button.frame = CGRect.init(x: 0, y: 0, width: 25, height: 25) //CGRectMake(0, 0, 30, 30)
    let barButton = UIBarButtonItem.init(customView: button)
    self.navigationItem.leftBarButtonItem = barButton
}

在此课程中navigationItem.titlenavigationItem.leftBarButtonItem无效。

此外,

我尝试在viewcontroller上设置

class HomeController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //Left Item Button
        let button = UIButton.init(type: .custom)
        button.setImage(UIImage.init(named: "menu"), for: UIControlState.normal)
        //button.addTarget(self, action:#selector(SSASideMenu.presentLeftMenuViewController), for: UIControlEvents.touchUpInside)
        button.frame = CGRect.init(x: 0, y: 0, width: 25, height: 25) //CGRectMake(0, 0, 30, 30)
        let barButton = UIBarButtonItem.init(customView: button)
        self.navigationItem.leftBarButtonItem = barButton

    }
...
}

注意:我尝试设置故事板不起作用......

0 个答案:

没有答案