如何修复iPhoneX后退按钮图像位置?

时间:2017-11-09 11:38:52

标签: ios swift uinavigationbar iphone-x

我遇到了iPhoneX后退按钮图像的问题。它没有在屏幕截图中看到的正确位置

enter image description here

我使用下面的代码设置背面图像

class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        UINavigationBar.appearance().backIndicatorImage = #imageLiteral(resourceName: "btn-back")
        UINavigationBar.appearance().backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "btn-back")
        UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -80.0), for: .default)
        return true
    }
}

任何人都可以解释为什么它处于不正确的位置以及如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以使用topItem?.title将导航标题设置为:

方法1:

self.navigationController?.navigationBar.topItem?.title = ""

<强>输出:

enter image description here

方法2:

 let yourBackImage = UIImage(named: "back-Image")
 self.navigationController?.navigationBar.tintColor = .red//.blue as you required
 self.navigationController?.navigationBar.backIndicatorImage = yourBackImage
 self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = yourBackImage
 self.navigationController?.navigationBar.topItem?.title = ""

<强>输出:

enter image description here

注意:作为Apple Human Interface GuideLine导航栏背面图片大小应为 -

  

75px×75px(3x)

enter image description here

样本图像3x(75 x 75) -

enter image description here