将工具栏添加到导航控制器 - 颜色不匹配
我使用以下代码向导航控制器添加多个按钮
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 44)];
toolbar.tintColor = [UIColor clearColor];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];
...
问题是工具栏的背景与导航栏不 100% 匹配。工具栏顶部显示一条小线。颜色几乎相同,但如果仔细观察,您可以看到矩形...
我在委托中执行以下操作来设置导航栏的背景,
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.0 green:.0 blue:.0 alpha:.4];
有什么想法如何使背景颜色与导航栏颜色相匹配吗?
I used following code to add multiple buttons to the navigation controller
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 44)];
toolbar.tintColor = [UIColor clearColor];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];
...
The problem is the background of the toolbar does not match 100% to the navigation bar. There is a small line showing at the top of the toolbar. The color is almost the same but if you look carefully you can see the rectangle …
I do following in the delegate to set the background of the navigation bar
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.0 green:.0 blue:.0 alpha:.4];
any ideas how to get the background color to match the navigation bar color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现此目的的最佳方法是使工具栏完全透明。实现此目的的一种方法是子类化 UIToolbar 并重写 drawRect: 以不执行任何操作。
这是我的 UITransparentToolbar 实现(请注意,这假设工具栏将通过 xib 创建。):
The best way to make this work is to make the toolbar fully transparent. One way to do this is to subclass UIToolbar and override drawRect: to do nothing.
Here's my implementation of a UITransparentToolbar (note this assumes the toolbar will be created via a xib.):
根据这个答案,iOS 5 或更高版本似乎无需技巧即可支持此功能:
https://stackoverflow.com/a/9109910/1179521< /a>
这对我有用!
Looks like iOS 5 or later supports this without a trick according to this answer:
https://stackoverflow.com/a/9109910/1179521
And it worked for me!