swiftuinavigationcontrolleruinavigationbarios11uinavigationitem

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


Solution

  • 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.