swift - TabView“点”索引颜色不变
问题描述
如果您使用.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))
}
}
[![ColorImage][1]][1]
[1]: https://i.stack.imgur.com/P25ST.png
解决方案
使用init
代替onAppear
struct TestScrollView: View {
init() {
UIPageControl.appearance().currentPageIndicatorTintColor = .blue
UIPageControl.appearance().pageIndicatorTintColor = .red
UIPageControl.appearance().tintColor = .red
}
var body: some View {
推荐阅读
- fortran - 如何知道 Fortran 中带有尾随空格的用户输入的长度?
- javascript - 代码只在第一次运行良好,之后它崩溃(DOM)
- c - 自动完成 unix 函数原型
- c# - 如何将文件动态添加到存储在 Azure Blob 存储中的 zip 存档?
- python - 找到我的鼠标位置。帮我
- java - 将 JSTL jar 包安装到 JSP 项目中
- google-maps - 谷歌街景是黑暗的(即使在官方服务网址上)
- javascript - 使 fontFamily cssproperty 单引号
- oracle - TNS的优势是什么?
- ruby-on-rails - 为什么允许非管理员用户访问我在 Rails 应用程序中的索引页面?(设计宝石)