Custom back button in UINavigationController

前端 未结 10 1816
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 16:59

For an application I\'m developing, I need to display a custom back button in a navigation bar. I have the button asset as a PNG image, and I\'m writing this code:



        
10条回答
  •  时光取名叫无心
    2020-12-28 17:38

    Johannes Fahrenkrug's Answer works, but the back image would appear at a very wired position.

    Here I found a better way to position the image at the right place:

    Make Sure You Have a back image with size 24x24(@1x) , I call it backImage

    Execute the following code when your app Launch

    UINavigationBar.appearance().barTintColor = nil
    UINavigationBar.appearance().backIndicatorImage = backImage
    UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)
    

提交回复
热议问题