gpt4 book ai didi

swift - 不使用 .barTintColor 设置导航栏的颜色?

转载 作者:行者123 更新时间:2023-11-28 07:27:41 26 4
gpt4 key购买 nike

我正在尝试显示用户图片来代替 rightBarButton,但是设置 UINavigationBarbarTintColor 会对图像进行着色。

enter image description here

AppDelegate 中,尝试:

UINavigationBar.appearance().barTintColor = .blue

viewDidLoad中,试过:

self.navigationController?.navigationBar.backgroundColor = .blue
self.navigationController?.navigationBar.tintColor = .blue
self.navigationController?.navigationBar.barTintColor = .blue

设置图片:

let avatarBtn = UIButton(type: .custom)
avatarBtn.frame = CGRect(x: 0.0, y: 0.0, width: 30, height: 30)
avatarBtn.setImage(UIImage(named:"myAvatar")?.withRenderingMode(.alwaysOriginal), for: .normal)

let menuBarItem = UIBarButtonItem(customView: avatarBtn)
menuBarItem.tintColor = .clear

self.navigationItem.rightBarButtonItem = menuBarItem

这些都没有用。如何设置没有色调的多色导航栏按钮?

提前致谢

最佳答案

更改tintColor

tintColor:应用于导航项和栏按钮项的色调。

关于swift - 不使用 .barTintColor 设置导航栏的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55945585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com