Dom*_*man 50 iphone shadow uinavigationbar ios6
在iOS 6中,即使您设置了自定义背景图像,也会在导航栏中自动添加投影.我很确定这不是iOS 5的情况,因为当我在iOS 5和6 sim中测试相同的代码时,阴影出现在iOS 6但不是5.
有人对这个有了解吗?或者如何启用/禁用它?
小智 141
将它放在AppDelegate中
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
// is IOS 7 and later
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
这就是为我做的事情.希望能帮助到你!
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
Run Code Online (Sandbox Code Playgroud)
Han*_*kke 57
我知道这已经通过上面更复杂的答案解决了,但这是我隐藏导航栏下阴影的最快捷最简单的方法.
self.navigationController.navigationBar.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)
Lee*_*ert 25
关于该shadowImage
财产主题的Apple开发文档的注意事项:
讨论:默认值为nil,对应于默认阴影图像.当非零时,此属性表示要显示的自定义阴影图像,而不是默认值.要显示自定义阴影图像,还必须使用setBackgroundImage:forBarMetrics:方法设置自定义背景图像.如果使用默认背景图像,则无论此属性的值如何,都将使用默认阴影图像.
因此,要使用nil UIImage hack,您还必须设置自定义导航栏背景图像.这也可以是一个零图像,这样就形成了一个漂亮的扁平,干净的"地铁"风格导航栏:
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
小智 19
你也可以尝试这个:
controller.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
Run Code Online (Sandbox Code Playgroud)
controller是一个UINavigationController.
一般,非NDA侵权答案:
如果您不想从图层中伸出一些东西,请将图层遮盖到其边界.
[self.layer setMasksToBounds:YES];
Run Code Online (Sandbox Code Playgroud)
如果它本身不起作用,请将高度明确设置为44(或iPhone上的横向为32).
小智 6
将shadowImage设置为空图像确实有效,但是,如果操作系统早于iOS 6,则呈现解决方案的方式会导致添加属性.
做一些依赖于属性或方法的更好的方法是:
if ([self.navigationController.navigationBar
respondsToSelector:@selector(shadowImage)]) {
self.navigationController.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
}
Run Code Online (Sandbox Code Playgroud)