更改选项卡式视图栏颜色 SwiftUI [英] Change Tabbed View Bar Color SwiftUI

查看:30
本文介绍了更改选项卡式视图栏颜色 SwiftUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何更改选项卡式视图底部栏的背景颜色?

Does anyone know how to change the background colour of a tabbed view bottom bar?

当我选择每个标签栏项目时,我已经设置了改变图标颜色的强调色.

I have set the accent colour which changed the colour of my icons when I select each tab bar item.

我尝试将背景设置为一种颜色,但它不会改变背景,并尝试将背景设置为图像只是为了确定,但这也没有任何作用.

I have tried setting the background to a colour but it doesn't change the back, and tried setting background to an image just to be sure but that also doesn't do anything.

想知道我是否需要以某种方式专门访问底部栏,然后在其上设置属性?

Wondering if I need to specifically access the bottom bar somehow and then set a property on that?

推荐答案

这里有一个解决方案.您可以更改 UITabBar 的 appearance 并更改 TabBar.

Here is a solution. You can change appearance of the UITabBar and change the 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"))
        }
    }
}

这篇关于更改选项卡式视图栏颜色 SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆