I can't set UINavigationBar's barTintColor to clearColor successfully

孤街浪徒 提交于 2019-12-23 10:17:17

问题


There's a strange iOS 7 thing about UINavigationBar. If you try to set it's barTintColor property to [UIColor clearColor] or any color with a alpha = 0, it totally ignores that value. So for instance, if you write:

[[navigationBar setBarTintColor:[UIColor clearColor]];

It doesn't respect the "clear" part at all. Same result with colorWithRed:green:blue:alpha.

But the most interesting part is, if you set translucent property to NO, then it will take the color you specified BUT with alpha 1. So if I specify colorWithRed:1 green:0 blue:0 alpha:0 it will be set to pure red with alpha as 1.

How can I achieve it? Is there any possible solution to make it a completely invisible barTintColor, although it requires hacky methods?


回答1:


If you want a clear navigation controller try setting the background image of the navigation controller to use a clear PNG file (1x1 transparent, no color).




回答2:


This works for me

navigationBar.translucent = true
navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)


来源:https://stackoverflow.com/questions/19737446/i-cant-set-uinavigationbars-bartintcolor-to-clearcolor-successfully

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!