Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 - Navigationbar large title custom offset

Is it possible to change the x-offset of the large navigation bar title? I would like to change the x-offset to 36pt.

The navigation bar

like image 905
evenwerk Avatar asked Oct 24 '17 11:10

evenwerk


3 Answers

I just discovered in the latest version of iOS 12, if you simply modify the layoutMargins property of the UINavigationBar, this will affect the large title.

let navigationBar = navigationController.navigationBar
navigationBar.layoutMargins.left = 36
navigationBar.layoutMargins.right = 36

I tried the solution mentioned here about using a custom NSMutableParagraphStyle. That does indeed work, but because it stretches the UILabel view that the large title is made of, when you swipe downwards, the subtle animation it plays where the text grows slightly becomes quite distorted.

like image 73
TiM Avatar answered Nov 20 '22 10:11

TiM


You can add additional offset this way:

if #available(iOS 11.0, *) {
    let navigationBarAppearance = UINavigationBar.appearance()
    let style = NSMutableParagraphStyle()
    style.alignment = .justified
    style.firstLineHeadIndent = 18
    navigationBarAppearance.largeTitleTextAttributes = [NSAttributedStringKey.paragraphStyle: style]
}
like image 40
Petr Slováček Avatar answered Nov 20 '22 09:11

Petr Slováček


You can't. You need to write your own NavigationController, by subclassing the UINavigationController for that.

like image 1
erik_m_martens Avatar answered Nov 20 '22 10:11

erik_m_martens