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
Format Uitextfield Text Without Having Cursor Move to the End
How to Get Navigation Based Template Functionality in Swift Programming
How to Xcodebuild a Static Library with Bitcode Enabled
How to Implement a Swiping/Sliding Animation Between Views
Iphone:How to Detect the End of Slider Drag
Tap on a Part of Text of Uilabel
Find List of Local Notification the App Has Already Set
Proper Use of Loadview and Viewdidload with Uiviewcontroller Without Nibs/Xibs
Nehotspothelper Annotations Not Appearing
How to Send Post Parameters in Swift
Pass Parameter in Webservice in Swift
How to Delay a Method Call for 1 Second
Uicollectionview Auto Scroll to Cell at Indexpath