iOS 11 - Navigationbar large title custom offset

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.


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]
}