
[英]Customizing UINavigationBar's barTintColor and title text color in Xcode 11.4
[英]Set Nav Bar's color without using .barTintColor?
我试图显示用户图片代替rightBarButton
但是设置UINavigationBar
barTintColor
使图像着色。
在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
:应用于导航项目和条形按钮项目的颜色颜色。
我使用了您的代码,但就我而言,我得到了预期的结果。 您正在使用哪种图像类型?
override func viewDidLoad() {
super.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:"myAvatar1")?.withRenderingMode(.alwaysOriginal), for: .normal)
let menuBarItem = UIBarButtonItem(customView: avatarBtn)
menuBarItem.tintColor = .clear
self.navigationItem.rightBarButtonItem = menuBarItem
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.