本文介绍了如何在SwiftUI中将.navigationBarTitle对齐方式更改为尾随iOS(或从右到左)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用UINavigationBar.appearance().titleTextAttributesUINavigationBar.appearance().backgroundColor修改了navigationBar的标题字体,颜色和背景.

I've modified the title font, color and background of navigationBar using UINavigationBar.appearance().titleTextAttributes and UINavigationBar.appearance().backgroundColor.

但是我找不到任何属性来将navigationBarTitle对齐方式设置为正确(跟踪).

However I can't find any attribute to set the navigationBarTitle alignment to right (trailing).

此外,我什至尝试了.navigationBarTitle(Text("Title").multilineTextAlignment(.leading))修饰符,但是SwiftUI不接受它.任何解决方案将不胜感激.

Additionally, I've even tried .navigationBarTitle(Text("Title").multilineTextAlignment(.leading)) modifier, but SwiftUI does not accept it. Any solution will be appreciated.

推荐答案

可以通过在修饰符下方添加view来从右至左更改任何:

It is possible to change any view right-to-left by giving them below modifiers:

.environment(\.layoutDirection, .rightToLeft)
.flipsForRightToLeftLayoutDirection(true)

它也可以用于导航栏:

NavigationView {

  VStack {

//Your views ...

    .navigationBarTitle(Text("Title"))
  }

}
.environment(\.layoutDirection, .rightToLeft)
.flipsForRightToLeftLayoutDirection(true)

这篇关于如何在SwiftUI中将.navigationBarTitle对齐方式更改为尾随iOS(或从右到左)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 22:03