はじめに
ナビゲーションバーボタンを実装するのにnavigationBarItems
を使用していましたが、
iOS14から非推奨らしいので代用のtoolbar
を使ってみます。
スクリーンショット
実装
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
Text("Hello, world!")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
} label: {
Text("左のボタン")
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
} label: {
Text("右のボタン")
}
}
}
}
}
}
おわり