ios - 如何修复 iPhone 后退按钮图像位置?

标签 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
    }
}

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

最佳答案

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

方法一:

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

输出:

enter image description here

方法二:

 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

关于ios - 如何修复 iPhone 后退按钮图像位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47200899/

相关文章:

objective-c - 在 objective-c 中使用渐变设置 NavigationBar 和 TabBar 背景颜色

ios - Objective C - 带动画的自定义 UIView 类初始化

ios - NSCache、镜像发布、异步队列

ios - 为什么当我删除 TableView 中的一行时它会删除多行?

iOS - 如何在数据准备好后以编程方式初始化和插入 UICollectionViewCell?

swift - Stripe 连接 IOS 集成

ios - 在 Swift 中从 UIButton 创建弹出窗口

ios - XCode 4.3.1 iPad模拟器

objective-c - 如何在 iOS7 中正确定位后退按钮

ios - 将 UIImageView 添加到 UINavigation 栏而不是导航 Controller 中