导航栏的色调颜色
当我使用以下代码设置色调颜色时,它可以工作
self.navigationController.navigationBar.tintColor = [UIColor BrownColor];
但是当我尝试设置色调颜色时,例如 - ` UIImage *navigationBarCol = [UIImage imageNamed:@"navigatorBar_color.png"];
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:navigationBarCol]; ` 然后它不会显示确切的颜色,只显示黑色阴影。 navigationBar_color.png 是我想要设置的颜色的单像素图像。 我正在使用此方法来设置程序中表行或其他对象的颜色,并且效果很好。
此外, UIColor colorWithPatternImage 方法应该返回 UIColor 因此这两种方法看起来也与我相似。您能告诉我为什么第二种方法对于 navigatiorBar 效果不佳吗?
When I set the tintcolor using following code it works
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
But When I try to set the tint color like -
` UIImage *navigationBarCol = [UIImage imageNamed:@"navigatorBar_color.png"];
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:navigationBarCol];
`
Then it does not show the exact color and only shows a shade of black.
navigationBar_color.png is a single pixel image of the color I want to set.
I am using this method to set the color of table rows or other objects in my program and it works fine.
Moreover UIColor colorWithPatternImage method is supposed to return UIColor so both the approach also look similar to me. Can you please tell me then why does the second approach does not work well for navigatiorBar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导航栏和控件上的tintColor仅用作计算控件中使用的渐变的基础。您不能很好地获得渐变图像,因此它只是使用其中的一部分。听起来您想要的是 UINavigationBar 的自定义子类,并具有重写的 drawRect: 方法。
The tintColor on NavigationBars and controls is only used as the basis to calculate the gradient used in the control. You can't very well have a gradient image, so it's just using part of it. It sounds like what you want is a custom subclass of UINavigationBar, with an overridden drawRect: method.