John Sorensen
John Sorensen

Reputation: 960

Swift UI padding on Navigation "back" button

How do I adjust the padding of a Swift UI "back" navigation button? i.e. the blue "Navigation" text in the image below (Image contributed by someone else on a different question). I want to add more space between the text and the leading edge of the screen.

enter image description here

Upvotes: 0

Views: 2429

Answers (1)

Asperi
Asperi

Reputation: 257573

You can use custom appearance for this purpose configured in the init of view holding NavigationView.

Here is a demo (with big offset for better visibility). Prepared with Xcode 13 / iOS 15.

init() {
    let appearance = UINavigationBarAppearance()
    appearance.backButtonAppearance.normal.titlePositionAdjustment = 
        UIOffset(horizontal: 40, vertical: 0)

    UINavigationBar.appearance().standardAppearance = appearance
}

enter image description here

Upvotes: 1

Related Questions