如果您使用.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)),那么您的标签栏将显示为一组点,指示您当前的页面索引。默认情况下它是白色的,我无法更改它。在下面的代码中,我将展示我围绕这个问题的所有尝试(它们都不起作用)。主要问题:如何改变点的颜色?PS:重要通知!在预览中,我看到了这些更改,但是当启动模拟器时,颜色就会消失。
struct ContentView: View {
var body: some View {
TabView {
Text("Home Tab")
.font(.system(size: 30, weight: .bold, design: .rounded))
.tabItem {
Text("Home")
}
Text("Bookmark Tab")
.font(.system(size: 30, weight: .bold, design: .rounded))
.tabItem {
Text("Bookmark")
}
}
.onAppear(){
UIPageControl.appearance().currentPageIndicatorTintColor = .blue;
UITabBar.appearance().tintColor = .red;
UITabBar.appearance().backgroundColor = UIColor.red
UITabBar.appearance().barTintColor = .red;
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
}
}
Run Code Online (Sandbox Code Playgroud)
[![ColorImage][1]][1]
[1]: https://i.stack.imgur.com/P25ST.png
Run Code Online (Sandbox Code Playgroud)
使用init而不是onAppear
struct TestScrollView: View {
init() {
UIPageControl.appearance().currentPageIndicatorTintColor = .blue
UIPageControl.appearance().pageIndicatorTintColor = .red
UIPageControl.appearance().tintColor = .red
}
var body: some View {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1895 次 |
| 最近记录: |