隐形导航栏
是否可以有一个不可见的导航栏背景?我以前见过定制的,但希望得到一些关于如何做到这一点的指导。
提前致谢!
Is it possible to have an invisible navigation bar background? I've seen custom ones before, but would love some guidance on how to do this.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在 UINavigationBar 或 UIToolbar 上获得透明背景,您必须将背景颜色设置为
[UIColor clearColor]
,将opaque
设置为 NO(如果尚未设置) ,并重写drawRect
以不绘制标准渐变背景。第三是棘手的部分。如果您直接使用 UINavigationBar,则只需对其进行子类化即可轻松覆盖
drawRect
。但我看到您用 UINavigationController 标记了它,因此您必须尝试用类别覆盖它。像这样的事情应该可以做到:它的缺点是应用程序中的每个导航栏现在都没有背景。如果你希望能够有一些透明和一些正常,你必须更进一步并混合
drawRect
以便你可以在需要时调用原始的:To get a transparent background on a UINavigationBar or UIToolbar, you have to set the background color to
[UIColor clearColor]
, setopaque
to NO (if it isn't already), and overridedrawRect
to not draw the standard gradient background. The third is the tricky part.If you're using UINavigationBar directly, you can easily enough just subclass it to override
drawRect
. But I see you tagged this with UINavigationController, so you'll have to try overriding it with a category. Something like this should do it:That has the drawback that every navbar in your app will now have no background. If you want to be able to have some transparent and some normal, you have to go one step further and swizzle
drawRect
so you can call the original when needed:就在今天,我自己(再次)查找了这个内容,有关此主题的一些不错的博客文章是:
http://idevrecipes.com/2011/01/12 /how-do-iphone-apps-instagramreederdailybooth-implement-custom-navigationbar-with-variable-width-back-buttons/
I was looking this up myself (again) just today, some good blog posts about this topic are:
http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/
http://idevrecipes.com/2011/01/12/how-do-iphone-apps-instagramreederdailybooth-implement-custom-navigationbar-with-variable-width-back-buttons/