简体   繁体   English

如何在 iOS 13 中设置 Tab Bar 标题?

[英]How to set the Tab Bar title in iOS 13?

I am trying to set a bigger font in the tab bar's title fields, but it doesn't work.我正在尝试在标签栏的标题字段中设置更大的字体,但它不起作用。 What I tried changes the size of the icon and the font of the text field in the view.我尝试更改图标的大小和视图中文本字段的字体。 The title in the bar remains unchanged.栏中的标题保持不变。 As you can see I tried many ways (commented lines) and neither of them works.如您所见,我尝试了很多方法(注释行),但它们都不起作用。

struct DetailView: View {

var vehicle: Vehicle

var body: some View {
    
    TabView {
       DataView()
        .tabItem {
            Text("Dane")
            .font(.system(size: 18.0, weight: .bold, design: .rounded))
            Image(systemName: "list.bullet")
//.font(.system(size: 30)).bold()//(Font.system(.largeTitle, design: .rounded).weight(.heavy).bold())
        }
        
        RefuelingListView()
            .font(.system(size: 20.0, weight: .bold, design: .rounded))
            .tabItem {
                Text("Wpisy")
                .bold()
                .font(Font.system(.largeTitle, design: .rounded).weight(.heavy))
                Image(systemName: "list.bullet")
               // .font(.system(size: 19))
        }//.font(.largeTitle)
   // }
         //   .textFieldStyle(PlainTextFieldStyle()).font(.system(size: 20))
 //        .onAppear() {
//            UITabBar.appearance().tintColor = .red
    }
    //.font(Font.system(.largeTitle, design: .rounded).weight(.heavy))
}
}

You can try adding a custom initializer for the tab bar like this:您可以尝试为标签栏添加自定义初始化程序,如下所示:

struct DetailView: View {

var vehicle: Vehicle

init() {
    UITabBarItem.appearance().setTitleTextAttributes([.font : UIFont.systemFont(ofSize: 20)], for: [])
}

var body: some View {
        // Rest of code
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM