【发布时间】:2020-07-12 19:27:53
【问题描述】:
我想给 UINavigationBar 一个静态高度,但我不完全确定该怎么做。目前,我有一个 UINavigationBar 视图修饰符,如下所示:
struct NavigationBarModifier: ViewModifier {
var backgroundColor: UIColor?
var titleColor: UIColor?
var largeTitleColor: UIColor?
var tintColor: UIColor?
init(backgroundColor: UIColor?, titleColor: UIColor?, largeTitleColor: UIColor?, tintColor: UIColor?) {
self.backgroundColor = backgroundColor
self.titleColor = titleColor
self.largeTitleColor = largeTitleColor
self.tintColor = tintColor
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithTransparentBackground()
coloredAppearance.backgroundColor = .clear
coloredAppearance.titleTextAttributes = [.foregroundColor: titleColor]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: largeTitleColor]
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
UINavigationBar.appearance().tintColor = tintColor
}
func body(content: Content) -> some View {
ZStack{
content
VStack {
GeometryReader { geometry in
Color(self.backgroundColor ?? .clear)
.frame(height: geometry.safeAreaInsets.top)
.edgesIgnoringSafeArea(.top)
Spacer()
}
}
}
}
}
我希望能够设置我已经为其创建了初始化程序的导航栏的高度,但我不太确定如何设置。我尝试做一些 UINavigationBar.appearance() 修饰符,但没有奏效
【问题讨论】:
-
@raynok 我该怎么做呢?
-
在下面查看我的答案。
标签: swift swiftui uinavigationbar navigationbar