我有一个应用程序,有时需要它的导航栏融入内容。
有人知道怎么去掉或者改变这个烦人的小条的颜色吗?
在下图中,我说的是根视图控制器下面1px的高度线
我有一个应用程序,有时需要它的导航栏融入内容。
有人知道怎么去掉或者改变这个烦人的小条的颜色吗?
在下图中,我说的是根视图控制器下面1px的高度线
当前回答
酒吧风格的黑色适合我。
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
我拥有的所有属性(以防万一):
[[UINavigationBar appearance] setBarTintColor:color];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
其他回答
这里有一个不使用任何图像的方法,这是唯一适合我的方法:
self.navigationController.navigationBar.layer.shadowOpacity = 0;
不幸的是,您需要在每个不希望出现该行的文件上执行此操作。在appDelegate中没有办法这样做。
编辑:
设置shadowColor为nil是不需要的,这是你唯一需要的行。
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIImage *emptyImage = [UIImage new];
self.navigationController.navigationBar.shadowImage = emptyImage;
[self.navigationController.navigationBar setBackgroundImage:emptyImage forBarMetrics:UIBarMetricsDefault];
}
编写自己的初始化式:D
import Foundation
import UIKit
extension UINavigationController {
convenience init(rootViewController : UIViewController, hidesShadow : Bool) {
self.init(rootViewController : rootViewController)
self.navigationBar.setValue(hidesShadow, forKey: "hidesShadow")
if hidesShadow {
self.extendedLayoutIncludesOpaqueBars = true
self.navigationBar.isTranslucent = false
}
}
}
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = Colors.color_app
appearance.titleTextAttributes = [.foregroundColor : UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor : UIColor.white]
appearance.shadowColor = .clear
appearance.shadowImage = UIImage()
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().barTintColor = Colors.color_app
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
}
设置背景图像的问题是它消除了模糊。您可以在不设置背景图像的情况下删除它。在这里看到我的答案。