ios - 为什么 iOS 11 中 Navigation backBarButtonItem 的位置出现了三个按钮?
<p><p>我已经设置了 UINavigation 栏外观,如下所示,</p>
<p>代码:</p>
<pre><code>fileprivate class func barButtonAppearance() {
var attributes = ()
attributes = UIFont(name: .Regular, size: 14)
attributes = 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
}
</code></pre>
<p>在我们在 iOS 11 中测试我们的应用程序之前,它一直运行良好。</p>
<p>如果我评论下面的代码</p>
<pre><code>let backImage =UIImage.image(assetID: .NavigationBarBack, caps: UIEdgeInsetsMake(0, 23, 0, 0)).withRenderingMode(.alwaysTemplate)
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default)
</code></pre>
<p>它工作正常,但默认苹果返回按钮。</p>
<p>这是出现的导航栏的屏幕截图,</p>
<p> <a href="/image/MgoVr.png" rel="noreferrer noopener nofollow"><img src="/image/MgoVr.png" alt="enter image description here"/></a> </p>
<p>我无法了解正在发生的事情。有人可以建议我解决方法吗?谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>UINavigationBar.appearance().backIndicatorImage = image.withRenderingMode(.alwaysOriginal)
UINavigationBar.appearance().backIndicatorTransitionMaskImage = image.withRenderingMode(.alwaysOriginal)
if #available(iOS 11, *) {
UIBarButtonItem.appearance().setTitleTextAttributes(, for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes(, for: .highlighted)
} else {
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -60, vertical: -60), for: .default)
}
</code></pre>
<p>图像是 UIImage。无需在每个 Controller 上创建基本 Controller 或编写代码。只需将这些行放在应用程序委托(delegate)中即可。</p></p>
<p style="font-size: 20px;">关于ios - 为什么 iOS 11 中 Navigation backBarButtonItem 的位置出现了三个按钮?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46404494/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46404494/
</a>
</p>
页:
[1]