ios - 在 TabBar SwiftUI 中更改选项卡选择颜色
问题描述
我正在尝试更改 TabBar 中选定选项卡的颜色,但没有任何效果。backgroundColor
我可以通过编写 来更改 TabBar
struct ContentView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.purple
}
var body: some View {
}
}
在swift中,我们设置tintColor
并且它确实改变了选定选项卡的颜色。但是我需要为 swiftUI 做什么?
这是我的代码,
TabView(selection: $selection) {
AView()
.tabItem {
VStack {
Image(systemName: "bubble.left.and.bubble.right")
Text("A Tab")
}
}.tag(0)
BView()
.tabItem {
VStack {
Image(systemName: "house")
Text("B Tab")
}
}.tag(1)
CView()
.tabItem {
VStack {
Image(systemName: "circle.grid.3x3")
Text("C Tab")
}
}.tag(2)
}
有什么帮助吗?提前致谢!!
解决方案
使用accentColor
:https ://developer.apple.com/documentation/swiftui/tabview/3368073-accentcolor
TabView {
// fill this out with your tabbed content
}
.accentColor(.orange)
推荐阅读
- bash - 如何让 bash 脚本在功能键按下时返回 true(用作 Sylpheed 过滤器)
- java - 在 java 中保存和加载不是字符串或 int 的对象
- azure - 运行 Docker 的 Azure 虚拟机上的“挂载:权限被拒绝”
- javascript - 让firebase返回一个排序的响应
- haskell - vim haskell 的符号和在 Haskell 中实现 SKI 的函数
- email-attachments - 如何通过 mailx 将标准输出作为附件发送?
- java - Spring Data MongoDB *在*保存到存储库后执行验证
- pimcore-v5 - 如何在 Pimcore v5 中设置 2 个相同类型的数据对象之间的父子关系?
- reactjs - 如何在本机反应中订购数组?
- docker - 在 Helm 图表 values.yaml 中拉取 docker hub 图像