我正在使用 tabView 在我的应用程序中显示一些入门屏幕。 我用的是
.onAppear() {
UIPageControl.appearance().currentPageIndicatorTintColor = .black
UIPageControl.appearance().pageIndicatorTintColor = .gray
}
修改指示器的背景和颜色。 但现在页面指示器在 iOS 14.5 设备中不显示。
引用了这个Link和其他多个链接,但它说要添加约束。如何在 swiftUI 中做到这一点?
将 init() 添加到定义 UIKit 外观的视图中。
struct YourView: View {
init() {
UIPageControl.appearance().currentPageIndicatorTintColor = .black
UIPageControl.appearance().pageIndicatorTintColor = .gray
}
var body: some View {
// Text("YourView") with TabView
}
}
你可以尝试给.tabViewStyle添加一个参数:
TabView(selection: $selectedPage) {
Text("1").tag(0)
Text("2").tag(1)
}
.tabViewStyle(.page(indexDisplayMode: .never))
这样您就不会更改应用程序中所有 UIPageControl 的外观。