首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ios 13中设置back按钮箭头色调的正确方法是什么

在ios 13中设置back按钮箭头色调的正确方法是什么
EN

Stack Overflow用户
提问于 2019-09-30 21:47:22
回答 2查看 3.5K关注 0票数 12

在iOS13中,苹果引入了新的UINavigationBarAppearance代理对象来设置导航栏的外观。我几乎可以设置我需要的所有东西,除了一个小东西。后退按钮的箭头总是以蓝色呈现,我不知道如何将其设置为我想要的颜色。我使用的是旧的[[UINavigationBar appearance] setTintColor:]方法,但我认为必须有某种方法来使用UINavigationBarAppearance对象API来完成这项工作。有人知道是怎么回事吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-14 21:23:43

设置外观(代理)的后退按钮颜色的新方法是:

代码语言:javascript
复制
let appearance = UINavigationBarAppearance()

// Apply the configuration option of your choice
appearance.configureWithTransparentBackground()
            
// Create button appearance, with the custom color
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]

// Apply button appearance
appearance.buttonAppearance = buttonAppearance

// Apply tint to the back arrow "chevron"
UINavigationBar.appearance().tintColor = UIColor.white

// Apply proxy
UINavigationBar.appearance().standardAppearance = appearance

// Perhaps you'd want to set these as well depending on your design:
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
票数 6
EN

Stack Overflow用户

发布于 2019-10-02 18:35:29

我在我的应用程序中有一个自定义的导航控制器设置,它根据不同的场景修改navigationBartitleTextAttributestintColor和其他。

在iOS 13上运行应用程序时,backBarButtonItem箭头具有默认的蓝色。视图调试器显示,只有UIBarButtonItemUIImageView具有这种蓝色。

我最后做的是两次设置navigationBar.tintColor,让它改变颜色...

代码语言:javascript
复制
public class MyNavigationController: UINavigationController, UINavigationControllerDelegate {

    public var preferredNavigationBarTintColor: UIColor?

    override public func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
    }


    public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

        // if you want to change color, you have to set it twice
        viewController.navigationController?.navigationBar.tintColor = .none
        viewController.navigationController?.navigationBar.tintColor = preferredNavigationBarTintColor ?? .white

        // following line removes the text from back button
        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

    }

寻找解决方案时最奇怪的部分是不一致的结果,这让我认为这与视图生命周期和/或外观动画或Xcode缓存有关:)

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58169259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档