Ho to add buttons and images to navigation bar in swiftUI NavigationView
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | / / / / ContentView.swift / / Testapp / / / / Created by Cairocoders / / import SwiftUI struct ContentView: View { @State var showAlert: Bool = false @State var msg: String = "" var body: some View { NavigationView { Text( "Cairocoders - tutorial101.blogspot.com" ) .navigationBarTitle( "Tutorials" ) .navigationBarItems(trailing: HStack { Button(action: { self .showAlert = true self .msg = "Reload button pressed..." }) { Text( "Reload" ) } Button(action: { self .showAlert = true self .msg = "Edit button pressed..." }) { Image(systemName: "person.crop.circle" ).imageScale(.large) / / SF Symbol } } ) } .alert(isPresented: $showAlert, content: { Alert(title: Text( self .msg)) }) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } |