Use navigationTitle(_:) with navigationBarTitleDisplayMode(_:)
navigationBarTitle(_:displayMode:)
Deprecated 非推奨
Availability 有効性
- iOS 13.0–15.4 Deprecated
- iPadOS 13.0–15.4 Deprecated
- Mac Catalyst 13.0–15.4 Deprecated
Technology
- Swift
UI
Declaration 宣言
func navigationBarTitle(_ titleKey: LocalizedStringKey
, displayMode: NavigationBarItem
.TitleDisplayMode
) -> some View
Parameters パラメータ
titleKey
A key to a localized description of this view to display in the navigation bar. ナビゲーションバーにおいて表示することになるこのビューのローカライズされた記述に対するキー。
displayMode
The style to use for displaying the navigation bar title.
Discussion 議論
Use navigation
to set the title of the navigation bar for this view and specify a display mode for the title from one of the Navigation
styles. This modifier only takes effect when this view is inside of and visible within a Navigation
.
In the example below, text for the navigation bar title is provided using a string.
下の例において、ナビゲーションバータイトルに対するテキストは、ある文字列を使って提供されます。
The navigation bar title’s Navigation
is set to .inline
which places the navigation bar title in the bounds of the navigation bar.
struct FlavorView: View {
let items = ["Chocolate", "Vanilla", "Strawberry", "Mint Chip",
"Pistachio"]
var body: some View {
NavigationView {
List(items, id: \.self) {
Text($0)
}
.navigationBarTitle("Today's Flavors", displayMode: .inline)
}
}
}
If the title
can’t be found, the title uses the text of the key name instead.