改变 SwiftUI 中 NavigationTitle 的字体大小

huangapple go评论54阅读模式
英文:

Change font size of NavigationTitle in SwiftUI

问题

我想将navigationTitle的字体大小更改为.footnote。我尝试搜索,但所有的解决方案都与navigationBarTitle有关。

以下是我的代码:

var body: some View {
    NavigationView {
        List {
            CoverImageView()
                .frame(height: 300)
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
        }
        .listStyle(PlainListStyle())
        .navigationTitle(Text("Title").font(.footnote))
    }
}
英文:

I wanted to change the font size of the navigationTitle to .footnote
I tried to search but all the solutions i came up on internet were related to navigationBarTitle

Here is my Code:

var body: some View {
    NavigationView {
        List {
            CoverImageView()
                .frame(height: 300)
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
        }
        .listStyle(PlainListStyle())
        .navigationTitle("Title")
//wanted to make "Title" appear as .footnote fontsize
    }
}

答案1

得分: 0

Changing the appearance of the UINavigationBar also seems to affect the navigationTitle:

struct ContentView: View {
    init() {
        UINavigationBar.appearance().largeTitleTextAttributes = [.font: UIFont.preferredFont(forTextStyle: .footnote)]
        UINavigationBar.appearance().titleTextAttributes = [.font: UIFont.preferredFont(forTextStyle: .footnote)]
    }

    var body: some View {
        NavigationView {
            List {
                CoverImageView()
                    .frame(height: 300)
                    .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
            }
            .listStyle(PlainListStyle())
            .navigationTitle("Title")
        }
    }
}

(Code based on link)

I hope this helps.

英文:

Changing the appearance of the UINavigationBar also seems to affect the navigationTitle:

struct ContentView: View {
    init() {
        UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont.preferredFont(forTextStyle: .footnote)]
        UINavigationBar.appearance().titleTextAttributes = [.font : UIFont.preferredFont(forTextStyle: .footnote)]
    }

    var body: some View {
        NavigationView {
            List {
                CoverImageView()
                    .frame(height: 300)
                    .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
            }
            .listStyle(PlainListStyle())
            .navigationTitle("Title")
        }
    }
}

(Code based on link)

I hope this helps.

huangapple
  • 本文由 发表于 2023年3月31日 04:02:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定