我如何更改导航栏的背景颜色
在我的导航栏中,我在左侧和右侧位置有两个按钮,在导航标题处有一个 segmentetControll 视图。 我想将导航栏的背景颜色更改为黑色,但其上项目的颜色将是另一种颜色。 我该怎么做? 我尝试将导航栏的色调颜色更改为黑色。 但我表明,segmentedControll 和导航栏上的按钮的颜色也更改为黑色。
提前致谢。
In my navigation bar i have two button at left and right position and a segmentetControll view at navigation title.
I want to change the background color of the navigation bar to black but thae color of the items on it will be another color.
how can i do it?
I try to chnage the tintColor of the navigationBar to black.
but i show that the color of the segmentedControll and the button on the navigationBar also changed to black.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将对象设置为导航栏的子视图。
设置色调颜色
将segmentedControl添加为viewControllers中的子视图,如下所示:
对于按钮,您应该尝试创建UIButtons而不是UIBarButtonsItems并将它们添加为子视图。如果您创建 UIBarButtonsItems 并像这样添加它们 self.navigationItem.rightBarButtonItem = tempButton;你会得到你所看到的效果。
如果您将它们添加为子视图,您不应该遇到您提到的问题..希望它有帮助。
try to set the objects as subviews to the navigationBar.
Set the tint color
Add the segmentedControl as a subview in the viewControllers like this:
For the buttons you should try creating UIButtons not UIBarButtonsItems and add them as subviews also. If you create UIBarButtonsItems and add them like this self.navigationItem.rightBarButtonItem = tempButton; you will get the effect that you saw.
if you add them as subviews you shouldn't have the problem you mentioned.. hope it helps.
您在导航栏中有一个名为“tintColor”的属性。您可以将其值设置为任何颜色。
You have the property called tintColor in navigation bar. You can set its value to any colour.