В SwiftUI 5 UINavigationBar.appearance (). TitleTextAttributes не работает. Для изменения шрифта в заголовке необходимо использовать одно из следующих средств:
init () {
UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(name: "Georgia", size: 20)!]
// OR
UINavigationBar.appearance().largeTitleTextAttributes = [.font:UIFont.preferredFont(forTextStyle:.text-style)]
}
где .text-style можно найти в документации UIFont.TextStyle, например
.caption
.body
.title1
.title2
.title3
etc
Обновление 1 (чтобы ответить на вопросы о точном коде в комментариях)
struct ContentView: View {
init () {
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
UINavigationBar.appearance().largeTitleTextAttributes = [.font:UIFont.preferredFont(forTextStyle:.title2),
.foregroundColor:UIColor.systemBlue,
.paragraphStyle: paragraph
]
...
то в теле у меня вот это. Вероятно, вам стоит обратить внимание на параметр displayMode
// Body is in the same ContentView struct. Settings from init will be used in navigationBarTitle
// listView() is just a custom function returning a SwiftUI's List()
var body: some View {
NavigationView {
listView()
.navigationBarTitle(
Text(self.accts.selCount <= 0 ? "Accounts" : "\(self.accts.selCount) selected")
,
displayMode:.large)
person
Oleg Gryb
schedule
05.10.2020