迅速更改后退栏按钮项目的颜色

时间:2019-12-09 21:21:09

标签: swift fonts colors uinavigationbar backbarbuttonitem

我正在尝试更改快速导航栏中后退按钮的颜色。

我最终希望为导航栏添加以下内容: enter image description here

这是我当前的代码,该代码为我提供了三个后退箭头作为后退按钮项,但是如何更改颜色,以便在一小段文本中出现三种不同的颜色? (绿色,黄色,红色)。

    func setCustomBackImage() {
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "<<<", style: .plain, target: nil, action: nil)
    }

2 个答案:

答案 0 :(得分:1)

这似乎与您所描述的类似:

enter image description here

如果您使用图像而不是标题作为条形按钮项目,则非常简单。

答案 1 :(得分:1)

还有一种更简单的方法,因为您说“ 我还挺新的”,那么您就可以了!

//add this in AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions 
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let backArrowImage = UIImage(named: "icon50")
let renderedImage = backArrowImage?.withRenderingMode(.alwaysOriginal)
UINavigationBar.appearance().backIndicatorImage = renderedImage
UINavigationBar.appearance().backIndicatorTransitionMaskImage = renderedImage
return true
// This will change all back-arrows to whatever image you want
}

此处“ icon50”应为“ <<<”图像。 Td:lr,使用图片。

希望它会有所帮助:)

相关问题