以下代码用于将自定义图像设置为的背景的非常精细:
// In AppDelegate.swift:
let image = UIImage(named:"HeaderBanner-new")
UINavigationBar.appearance().setBackgroundImage(image, for: UIBarMetrics.defaultPrompt)由于切换到Xcode 9、Swift 4和iOS 11,此代码不再工作。我得到的只是UINavigationBar中的纯白背景。
我还尝试将代码从AppDelegate.swift中移出并直接放在根自定义UINavgiationController.swift文件中:
let image = UIImage(named:"HeaderBanner-new")
self.navigationBar.setBackgroundImage(image, for: UIBarMetrics.defaultPrompt)还是不起作用。有什么想法--或者解决办法/黑客的想法?
发布于 2017-11-20 15:31:52
NavigationBar.setBackgroundImage似乎不像iOS 11中预期的那样工作。
我也有同样的问题,并通过使用NavigationBar.barTintColor修复了它,它起了作用。
请参考this answer。
https://stackoverflow.com/questions/46775647
复制相似问题