TabView“点"索引颜色不变 [英] TabView "dot" index color does not change
问题描述
如果您使用 .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
那么您的标签栏将显示为一组点,表示您当前的页面索引.默认情况下它是白色的,我不能改变它.在下面的代码中,我将展示我对这个问题的所有尝试(它们都不起作用).主要问题:如何改变点的颜色?PS:重要通知!在预览时我看到了这些变化,但是当启动模拟器时颜色消失了.
struct ContentView: 查看 {var主体:一些视图{标签视图{文本(主页选项卡").font(.system(size: 30, weight: .bold, design: .rounded)).tabItem {文本(首页")}文本(书签标签").font(.system(size: 30, weight: .bold, design: .rounded)).tabItem {文本(书签")}}.onAppear(){UIPageControl.appearance().currentPageIndicatorTintColor = .blue;UITabBar.appearance().tintColor = .red;UITabBar.appearance().backgroundColor = UIColor.redUITabBar.appearance().barTintColor = .red;}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)).indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))}}
<预><代码>[![彩色图像][1]][1][1]:https://i.stack.imgur.com/P25ST.png
使用 init
而不是 onAppear
struct TestScrollView:查看{在里面() {UIPageControl.appearance().currentPageIndicatorTintColor = .blueUIPageControl.appearance().pageIndicatorTintColor = .redUIPageControl.appearance().tintColor = .red}var主体:一些视图{
If you use .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
then your tab bar will be displayed as a group of dots, indicating you current page index.
By default it has white color and I can't change it.
In code below I'll show all my tries around this problem (none of them works). The main question: how to change the dots color?
PS: Important notice! On preview I see these changes, but when starts the simulator then the colouring disappears.
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))
}
}
[![ColorImage][1]][1]
[1]: https://i.stack.imgur.com/P25ST.png
Use init
instead of onAppear
struct TestScrollView: View {
init() {
UIPageControl.appearance().currentPageIndicatorTintColor = .blue
UIPageControl.appearance().pageIndicatorTintColor = .red
UIPageControl.appearance().tintColor = .red
}
var body: some View {
这篇关于TabView“点"索引颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!