我制作了一个类似于下面看到的苹果列表的列表,但我真的不喜欢 UInavigation 栏的样子。理想情况下,我希望它更小或将其隐藏,以便我可以将自己的视图放在那里。
我尝试使用苹果外观 api 中的以下内容来隐藏它
init() {
UINavigationBar.appearance().backgroundColor = .green
UINavigationBar.appearance().isHidden = true
}
与巨大的标题相比,即使有这样的导航栏也会更理想
但这没有影响,有没有人有任何建议或想法,我如何可以将其定制为更像我想要的那样?
这是我使用 swiftUI 和一些 UINavigationView 所实现的,我相信这些修饰符将在 beta 后实现到 swiftUI 中。
我通过调整 max 关于 UINavigationBar 外观的想法来实现这一点。如何更改导航栏中的背景或颜色? https://stackoverflow.com/questions/56773511/how-can-be-changed-the-background-or-the-color-in-the-navigation-bar
除此之外,我只是将切换开关切换到导航栏标题视图
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)
}
})
}
以下是唯一不是 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)]
}
是的,记得将导航栏标题模式设置为内联:
.navigationBarTitle(Text("Home"), displayMode: .inline)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)