有没有办法让导航控制器的栏完全透明?
我尝试过的:
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];
[self.navigationController.navigationBar setAlpha:0.0];
Run Code Online (Sandbox Code Playgroud)
但酒吧的外观不会改变,并保持白色半透明.我试图看到酒吧项目,但不是酒吧本身.有人能指出我正确的方向吗?谢谢
如何在SwiftUI中更改导航栏标题颜色
NavigationView {
List{
ForEach(0..<15) { item in
HStack {
Text("Apple")
.font(.headline)
.fontWeight(.medium)
.color(.orange)
.lineLimit(1)
.multilineTextAlignment(.center)
.padding(.leading)
.frame(width: 125, height: nil)
Text("Apple Infinite Loop. Address: One Infinite Loop Cupertino, CA 95014 (408) 606-5775 ")
.font(.subheadline)
.fontWeight(.regular)
.multilineTextAlignment(.leading)
.lineLimit(nil)
}
}
}
.navigationBarTitle(Text("TEST")).navigationBarHidden(false).foregroundColor(.orange)
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过,.foregroundColor(.orange)但是没有用
也尝试过 .navigationBarTitle(Text("TEST").color(.orange))
有什么帮助吗?
首先,我已经看到了如何在IOS 8中制作UINavigationBar透明的 所有答案?透明UINavigationBar和Make UINavigationBar透明.
他们似乎并不适合我.
我的常规视图控制器(在尝试使导航栏透明之前)没有任何问题:
我正在使用(在viewDidLoad和中试过viewWillAppear:):
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
我明白了:
灰色状态栏背景,完全白色导航栏,不与状态栏混合,然后视图开始.其他问题"答案"中的所有"解决方案"对我来说都会产生相同的结果.
我也尝试过设置self.edgesForExtendedLayout = UIRectEdgeNone;,self.edgesForExtendedLayout = UIRectEdgeAll;但这也没有任何影响.
如何在不弄乱所有内容的情况下使导航栏透明?
更新:在Warif Akhand Rishi的回答之后,我已经改变self.navigationController.view.backgroundColor = [UIColor clearColor];了self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];,现在我得到一个灰色,统一的状态/导航栏,但仍然不透明:
更新2:我已经连接了视图调试器,并且灰色背景似乎来自视图层次结构的根本深处,并且我的视图内容没有扩展.我self.edgesForExtendedLayout = UIRectEdgeAll;再次尝试使用最新的代码,但仍无济于事:
我是iOS快速开发的新手,我遇到了一个问题.我想设置透明导航栏并使透明导航栏和状态栏的图像底层如下图所示,

但在我实现以下代码后,
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController!.navigationBar.translucent = true
Run Code Online (Sandbox Code Playgroud)
结果是图像仍然在导航栏和状态栏下方,即使我将导航栏设置为透明.

tl;博士
我正在尝试为UINavigationBar. 有没有办法配置导航栏,使其使用scaleAspectFill类似行为(作为UIImageViewwith contentModeset to scaleAspectFill)?
目标
我有一张图像大致适合横向 iPhone 的导航栏尺寸(64pt 高度,大约 800pt 宽度;不过,确切的尺寸在这里无关紧要),我用navigationBar.setBackgroundImage(img, for: .default). 图像是一张模糊的照片,所以不需要像素完美。顺便说一句 - 我正在使用UINavigationBar.appearance一次为所有导航栏设置背景。
我想要它做什么:在纵向时显示图像的中心部分,在横向时显示完整图像而不进行裁剪。如果高度不完全匹配(正如在 iPhone X 上预期的那样),它应该放大一点以填充额外的高度。
作为后备解决方案,如果较小宽度的图像显示居中并通过拉伸第一个和最后一个像素列来填充额外的水平空间,我也会接受。
到目前为止我尝试过的
contentModeof UINavigationBar-- 似乎被忽略stretchableImage(withLeftCapWidth:topCapHeight:)- 填充导航栏但图像被推到右下角(显然是因为此方法仅将左侧和顶部视为可拉伸的边距)resizableImage(withCapInsets:resizingMode:)使用resizingModeset to使其可调整大小stretch- 在横向中它只是将图像拉伸到全宽,而忽略了大写插图(可能这种方法并没有按照我的想法行事)。