更改UINavigationBar后退按钮图像

时间:2015-02-04 14:21:41

标签: ios swift uinavigationcontroller uinavigationbar uinavigationitem

我正在尝试更改UIBarButtonItem中按钮的图像。但我无法改变它。它仍然显示旧图像。

func showLogo(type:LogoType)
    {
            var logoName = "logo.png"
            var hightlightedLogoName = "logo_highlight.png"

            if (type == .Book){
                logoName = "logo_book.png"
                hightlightedLogoName = "logo_highlight_book.png"
            }

            let logoImage = UIImage(named: logoName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

            var logo_button = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
            logo_button.setBackgroundImage(logoImage, forState: UIControlState.Normal)
            logo_button.setBackgroundImage(UIImage(named:hightlightedLogoName), forState: UIControlState.Highlighted)
            logo_button.frame = CGRectMake(0, 0, logoImage!.size.width, logoImage!.size.height)
            logo_button.addTarget(self, action: "logoPressed", forControlEvents: .TouchUpInside)
            var logoButton:UIBarButtonItem = UIBarButtonItem(customView: logo_button)
            self.navigationItem.leftBarButtonItem = logoButton

    }

函数调用

self.showLogo(.Other) //Shows Default Logo

当我推到另一个屏幕时。我正在调用相同的函数

self.showLogo(.Book) //Shows Default Logo. Should Display Book Logo

我的代码有什么问题。

0 个答案:

没有答案