How to Put a Logo in Navigationview in Swiftui

How to set image for NavigationBar title using SwiftUI?

In SwiftUI 2 you can create a ToolbarItem with the principal placement:

struct ContentView: View {
var body: some View {
NavigationView {
Text("Test")
.toolbar {
ToolbarItem(placement: .principal) {
Image(systemName: "ellipsis.circle")
}
}
}
}
}

How to show App Logo in All Navigation Bar in SwiftUI App

A possible approach is to use instead ZStack with top alignment, like

var body: some View {
ZStack(alignment: .top) { // << here !!

Image(systemName: "heart.fill")
.foregroundColor(.red).zIndex(1)

NavigationStack {
content()
.navigationDestination(for: String.self) { stringValue in
Text("Detail")
}
}

SwiftUI - How to add an Image beside the title in the navigationbar?

here is the code:

struct ContentView: View {
var body: some View {

NavigationView{

Text("Hello")

.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Title")
.font(.title)
}

ToolbarItem(placement: .navigationBarTrailing) {
Image(Constants.logoImage).resizable()
.scaledToFit()
.frame(width: 100, height: 50, alignment: .trailing)
}
}
}
}
}

SwiftUI - How to add an Image beside the title in the navigationbar?

here is the code:

struct ContentView: View {
var body: some View {

NavigationView{

Text("Hello")

.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Title")
.font(.title)
}

ToolbarItem(placement: .navigationBarTrailing) {
Image(Constants.logoImage).resizable()
.scaledToFit()
.frame(width: 100, height: 50, alignment: .trailing)
}
}
}
}
}


Related Topics



Leave a reply



Submit