toolbarTitleAlignment
The alignment the navigation bar resolved for its title.
Declaration
var toolbarTitleAlignment: ToolbarTitleAlignment { get set }Discussion
Read this from a custom title view (like a ToolbarItem using the title placement) to lay out its content to match the alignment the system chose.
When the system has resolved an alignment for the title, this reports that concrete alignment, leading or center, even when you have not set a preference with toolbarTitleAlignment(_:). Otherwise it is automatic.
struct AlbumTitle: View {
@Environment(\.toolbarTitleAlignment) private var alignment
var body: some View {
VStack(alignment: alignment == .leading ? .leading : .center) {
Text("Library")
Text("42 Albums").font(.caption)
}
}
}Use this to align content within the size your view already reported, not to decide that size.