- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用新的 UINavigationBarAppearance
时,似乎没有(或者至少没有明显的)方法来更新 View Controller 上的导航样式 apis .虽然这些 API 远远优于旧的样式方法,特别是在需要透明导航栏时,但我需要多个应用程序能够在透明导航和不透明导航之间切换。
有人知道解决这个问题的方法吗?或者我可能会错过什么?下面是示例代码!
var styles: [UINavigationBarAppearance] = {
let style1 = UINavigationBarAppearance()
style1.configureWithOpaqueBackground()
style1.backgroundColor = .white
style1.titleTextAttributes = [.foregroundColor: UIColor.black]
style1.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
let buttonAppearance = UIBarButtonItemAppearance()
buttonAppearance.normal.titleTextAttributes = [
.foregroundColor: UIColor.black
]
style1.buttonAppearance = buttonAppearance
let style2 = UINavigationBarAppearance()
style2.configureWithOpaqueBackground()
style2.backgroundColor = .systemBlue
style2.titleTextAttributes = [.foregroundColor: UIColor.systemGreen]
style2.largeTitleTextAttributes = [.foregroundColor: UIColor.systemGreen]
let button2Appearance = UIBarButtonItemAppearance()
button2Appearance.normal.titleTextAttributes = [
.foregroundColor: UIColor.systemGreen
]
style2.buttonAppearance = button2Appearance
let style3 = UINavigationBarAppearance()
style3.configureWithTransparentBackground()
style3.titleTextAttributes = [.foregroundColor: UIColor.systemBlue]
style3.largeTitleTextAttributes = [.foregroundColor: UIColor.systemBlue]
let button3Appearance = UIBarButtonItemAppearance()
button3Appearance.normal.titleTextAttributes = [
.foregroundColor: UIColor.systemBlue
]
style3.buttonAppearance = button3Appearance
return [style1, style2, style3]
}()
var currentStyle: UINavigationBarAppearance?
override func viewDidLoad() {
currentStyle = styles.first
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func switchNavigavigationStyles(_ sender: Any) {
guard let currentStyle = currentStyle else {
return
}
guard let styleIndex = styles.firstIndex(of: currentStyle) else {
return
}
var nextIndex = styleIndex + 1
if nextIndex == styles.count {
nextIndex = 0
}
navigationController?.navigationBar.scrollEdgeAppearance = styles[nextIndex]
navigationController?.navigationBar.compactAppearance = styles[nextIndex]
navigationController?.navigationBar.standardAppearance = styles[nextIndex]
navigationController?.navigationBar.setNeedsDisplay() // Attempting to force it to redraw!
navigationController?.view.setNeedsDisplay()
self.currentStyle = styles[nextIndex]
}
最佳答案
明白了!因此,在重新观看 WWDC 视频后,似乎需要在特定屏幕上进行配置,设置 navigationItem.standardAppearance
等。已尝试使用它来代替,它似乎可以完成工作!
关于ios - View Controller 出现后 UINavigationBarAppearance 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58318955/
Xcode 版本 11.0 beta 5 (11M382q) 当我的 View Controller 之一是顶部 View Controller 时,我正在使用新的外观 API 为条形按钮项目着色。我
我有一个 iOS 应用程序,它使用自定义后 V 形作为导航栏中的后退按钮,并具有自定义背景颜色和阴影等。我想将背面指示器图像的颜色设置为默认蓝色以外的颜色。我如何使用新的 UINavigationBa
问题 我有一个应用程序,它为不同的流程提供不同颜色的导航栏。一些导航栏有浅色背景,需要黑色状态栏文本。其他的导航栏较暗,需要白色的状态栏文本。 作为迁移到 iOS15 的一部分,我更新了我正在开发的应
使用新的 UINavigationBarAppearance 时,似乎没有(或者至少没有明显的)方法来更新 View Controller 上的导航样式 apis .虽然这些 API 远远优于旧的样式
如何使用这个新对象来自定义 iOS 13 中的导航栏?我在 Objective-C 中尝试了以下代码,但它无法正常工作。当 View Controller 被推送或弹出到导航堆栈时,它只显示我的标题文
我有一个自定义颜色导航栏,我需要确保状态栏颜色设置为白色。在 iOS 13 之前,这很容易做到,这是 UIViewController 中的一个代码片段,它可以很好地完成这项工作: override
如果我像这样创建一个 UINavigationBarAppearance... let app = UINavigationBarAppearance(idiom: .pad) ...并为其配置背景颜
我是一名优秀的程序员,十分优秀!