有谁知道如何更改选项卡式视图底部栏的背景颜色?
当我选择每个标签栏项目时,我已经设置了改变图标颜色的强调色。
我尝试将背景设置为一种颜色,但它不会改变背景,并尝试将背景设置为图像只是为了确定,但这也没有任何作用。
想知道我是否需要以某种方式专门访问底部栏,然后在其上设置一个属性?
Mar*_*ens 29
barTintColor
和isTranslucent
出于某种原因,当我只使用barTintColor
或什至使用backgroundColor
. 我也必须包括在内isTranslucent
。
这是我命名的颜色:
barTintColor
(如您所见,它略有褪色)
backgroundColor
(这会使条形变暗一点)
barTintColor
&isTranslucent
为 False这个组合对我来说是什么:
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor(named: "Secondary")
Run Code Online (Sandbox Code Playgroud)
mum*_*umu 22
这是一个解决方案。您可以更改appearance
UITabBar 并更改 TabBar。
struct TabView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.blue
}
var body: some View {
return TabbedView {
Text("This is tab 1").tag(0).tabItemLabel(Text("tab1"))
Text("This is tab 2").tag(1).tabItemLabel(Text("tab2"))
Text("This is tab 3").tag(2).tabItemLabel(Text("tab3"))
}
}
}
Run Code Online (Sandbox Code Playgroud)
Yar*_*arm 16
在 init() 添加 UITabBar.appearance().barTintColor = UIColor.blue
struct ContentView: View {
@State private var selection = 1
init() {
UITabBar.appearance().barTintColor = UIColor.blue
}
var body: some View {
TabView (selection:$selection){
Text("The First Tab")
.tabItem {
Image(systemName: "1.square.fill")
Text("First")
}
.tag(1)
Text("Another Tab")
.tabItem {
Image(systemName: "2.square.fill")
Text("Second")
}.tag(2)
Text("The Last Tab")
.tabItem {
Image(systemName: "3.square.fill")
Text("Third")
}.tag(3)
}
.accentColor(.white)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
它在最新版本中对我有用
var body: some View {
TabView{
Text("Zain ahmed")
.font(.system(size: 30, weight: .bold, design: .rounded))
.tabItem {
Label("Home", systemImage: "house.fill")
}
Text("Bookmark Tab")
.font(.system(size: 30, weight: .bold, design: .rounded))
.tabItem {
Label("Bookmark", systemImage: "bookmark.circle.fill")
}
}
.onAppear() {
UITabBar.appearance().backgroundColor = .lightGray
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18455 次 |
最近记录: |