Back button not set correctly in iOS 11

We started work on our project with Xcode 8.3, and everything was fine until iOS 10, but when we launch our application in iOS 11, the return button does not align as you see in the image below

iOS 11 screenshot

But with iOS 10 it is correctly aligned

iOS 10 Screenshot

And this is what we get with the layout restriction error

(
"<NSLayoutConstraint:0x600000288200 _UIModernBarButton:0x7f7ef5c87f10.bottom == UILayoutGuide:0x6000005a0380'UIViewLayoutMarginsGuide'.bottom + 64.5   (active)>",
"<NSLayoutConstraint:0x600000287f30 V:[_UIModernBarButton:0x7f7ef5c87f10]-(>=0)-|   (active, names: '|':_UIButtonBarButton:0x7f7ef5c86e60 )>",
"<NSLayoutConstraint:0x600000282030 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x6000005a0380'UIViewLayoutMarginsGuide']-(16)-|   (active, names: '|':_UIButtonBarButton:0x7f7ef5c86e60 )>"

)

+4
source share
2 answers

For me, this is because I use some tricks as shown below to hide the title

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -1000), for: .default)

We should not do this, it does not work on iOS 11 and will trigger a lot of problems with the automatic layout as you publish. Therefore, check if there is a button appearanceon the rear panel.

"", fooobar.com/questions/106799/...

+4
UINavigationBar.appearance().backIndicatorImage = image.withRenderingMode(.alwaysOriginal)
UINavigationBar.appearance().backIndicatorTransitionMaskImage = image.withRenderingMode(.alwaysOriginal)

    if #available(iOS 11, *) {
        UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
        UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .highlighted)
    } else {
        UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -60, vertical: -60), for: .default)
    }
+1

Source: https://habr.com/ru/post/1687413/


All Articles