wol*_*fan 48
这在带有半透明导航的iOS7上不起作用......
来自Apple文档的粘贴;
描述用于导航栏的阴影图像.默认值为nil,对应于默认阴影图像.当非零时,此属性表示要显示的自定义阴影图像,而不是默认值.要显示自定义阴影图像,还必须使用setBackgroundImage:forBarMetrics:方法设置自定义背景图像.如果使用默认背景图像,则无论此属性的值如何,都将使用默认阴影图像.
所以基本上你需要实现setBackgroundImage. 另外请注意,在iOS7上你将不再使用外观,但你将在viewController上下文中修改导航栏.
那是:
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我把它放在viewDidLoad中(可以为UINavigationViewController中的每个UIViewController添加自定义行为).
muf*_*ffe 46
如果我理解你正确的尝试
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
Run Code Online (Sandbox Code Playgroud)
use*_*951 12
基于muffed2k回答+编程Thomas评论,这是我用来显示没有背景图像(ios5.1/6.0)和没有底部边框(ios7.0)的UINavigationBar:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6)
{
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
}else
{
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用Swift并遇到此问题,请在主ViewController中尝试:
override func viewDidLoad() {
super.viewDidLoad()
/// ...
navigationController?.navigationBar.shadowImage = UIImage();
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
//...
}
Run Code Online (Sandbox Code Playgroud)
基于@ wolffan的上述答案