我已经设置了 UINavigation 栏外观,如下所示,
代码:
fileprivate class func barButtonAppearance() {
var attributes = [String : AnyObject]()
attributes[NSFontAttributeName] = UIFont(name: .Regular, size: 14)
attributes[NSForegroundColorAttributeName] = UIColor.descriptionColor()
UIBarButtonItem.appearance().setTitleTextAttributes(attributes, for: UIControlState())
let backImage = UIImage.image(assetID: .NavigationBarBack, caps: UIEdgeInsetsMake(0, 23, 0, 0)).withRenderingMode(.alwaysTemplate)
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default)
UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage
}
在我们在 iOS 11 中测试我们的应用程序之前,它一直运行良好。
如果我评论下面的代码
let backImage = UIImage.image(assetID: .NavigationBarBack, caps: UIEdgeInsetsMake(0, 23, 0, 0)).withRenderingMode(.alwaysTemplate)
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default)
它工作正常,但默认苹果返回按钮。
这是出现的导航栏的屏幕截图,
我无法了解正在发生的事情。有人可以建议我解决方法吗?谢谢。
Best Answer-推荐答案 strong>
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)
}
图像是 UIImage。无需在每个 Controller 上创建基本 Controller 或编写代码。只需将这些行放在应用程序委托(delegate)中即可。
关于ios - 为什么 iOS 11 中 Navigation backBarButtonItem 的位置出现了三个按钮?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/46404494/
|