yaw*_*eix 6 uinavigationbar swiftui
我做了一个类似于下面看到的苹果的列表,但我真的不喜欢 UInavigation 栏的样子。理想情况下,我希望它更小或将其隐藏,以便我可以将自己的观点放在那里。
我试图通过使用苹果外观 api 中的以下内容来隐藏它
init() {
UINavigationBar.appearance().backgroundColor = .green
UINavigationBar.appearance().isHidden = true
}
Run Code Online (Sandbox Code Playgroud)
与拥有巨大的标题相比,即使拥有这样的导航栏也会更理想
但这没有影响,有没有人有任何建议或想法,我可以如何自定义它以使其更像我想要的那样?
这就是我使用 swiftUI 和一些 UINavigationView 所实现的,我相信这些修饰符将在测试版之后实现到 swiftUI。
我通过调整 max 关于 UINavigationBar 外观的想法来实现这一点。如何更改导航栏中的背景或颜色?
除此之外,我只是切换到 NavigationBar 标题的视图
var body: some View {
VStack {
if displayImg {
Image("dontstarve")
.resizable()
.aspectRatio(contentMode: .fill)
.edgesIgnoringSafeArea(.all)
} else {
Image(systemName: "play")
}
}
.navigationBarTitle(Text("Adjustment"), displayMode: .inline)
.navigationBarItems(trailing:
HStack {
Toggle(isOn: $displayImg) {
Text("\(self.displayImg ? "on" : "off")")
.foregroundColor(Color.white)
}
})
}
Run Code Online (Sandbox Code Playgroud)
下面是唯一不是 SwiftUI 的代码。我只是将它们全部放入 init() 中:
init() {
UINavigationBar.appearance().tintColor = .systemGray6
UINavigationBar.appearance().barTintColor = .systemTeal
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 25)]
}
Run Code Online (Sandbox Code Playgroud)
是的,记住将导航栏标题模式设置为内联:
.navigationBarTitle(Text("Home"), displayMode: .inline)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7534 次 |
最近记录: |