ios - 如何在 SwiftUI 的导航栏中添加“副标题”之类的内容?
问题描述
“我的”解决方案:
感谢Midhun MP和Mojtaba Hosseini的帮助,我找到了这个解决方案。它工作正常,但导航栏的半透明效果不再起作用。所以,如果有人知道如何解决它,请告诉我。
// UITableView.appearance().backgroundColor = UIColor(named: "CustomTableViewBackgroundColor") // These are all custom color sets
// UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomTableViewCellBackgroundColor")
// For the navigation bar color
UINavigationBar.appearance().backgroundColor = UIColor(named: "CustomNavigationBarBackgroundColor")
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
return VStack(spacing: 0) {
// This is the "subheader"
Text("Test")
.padding(.top, 9.5)
.padding(.bottom, 8)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color("CustomNavigationBarBackgroundColor")) // This is also a custom color set
.font(.footnote)
// And here is my normal NavigationView
NavigationView {
List {
Text("Hello")
} .listStyle(GroupedListStyle())
.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarBackButtonHidden(true)
.navigationBarItems(
leading:
Button("Cancel") {
// self.presentationMode.wrappedValue.dismiss()
}.padding(.vertical, 5),
trailing:
Button("Done") {
}.padding(.vertical, 5).disabled(true)
)
}
}
我原来的问题:
我想在我的导航栏中插入这样的内容。因此,如果有人可以帮助我,那就太好了。
我现在的代码
NavigationView {
List {
Text("Hello")
} .listStyle(GroupedListStyle())
.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarBackButtonHidden(true)
.navigationBarItems(
leading:
Button("Cancel") {
self.presentationMode.wrappedValue.dismiss()
},
trailing:
Button("Done") {
}.disabled(true)
)
}
还有一张我的代码看起来如何编译的照片
解决方案
您可以在导航视图之前添加一个文本。
struct ContentView: View {
var body: some View {
VStack {
Text("Sub Header")
NavigationView {
List {
Text("Hello")
} .listStyle(GroupedListStyle())
.navigationBarTitle(Text("Hello There"), displayMode: .inline)
.navigationBarBackButtonHidden(true)
.navigationBarItems(
leading:
Button("Cancel") {
//self.presentationMode.wrappedValue.dismiss()
},
trailing:
Button("Done") {
}.disabled(true)
)
}
}
}
}
注意:如果您转到详细信息页面,上述子标签仍将可见。如果您不想这样,您可以使用普通视图创建自定义标题。
推荐阅读
- bash - 从文件 B 的列表中删除文件 A 中的所有单词
- kubernetes - Kubernetes kubectl 显示 pod 重新启动为零,但 pod 年龄已更改
- windows - 如何在 Windows 批处理文件中使用 WMIC 将 DLL 或 EXE 的文件版本获取到变量?
- javascript - 为什么我的异步函数不与回调结合产生结果?
- docker - 更改通过 Kubernetes 中的 pod 配置文件创建的默认容器名称
- java - 我的字符串排列算法不起作用
- javascript - 当模块在本地注册域中发布时如何安装 npm 依赖模块?
- swift - 滚动加载:信号量还是布尔值?
- spring-boot - 无法让 Prometheus 与 Spring Boot 2.0.3 一起使用
- regex - 使用正则表达式在ansible playbook中将段落与大文本分开