gpt4 book ai didi

ios - 设置 UIBarButtonItem.appearance() 在 iOS 15 上不起作用

转载 作者:行者123 更新时间:2023-12-05 00:43:33 26 4
gpt4 key购买 nike

如何在 UINavigationBar

上设置全局外观 UIBarButtonItem

UIBarButtonItem.appearance() 不适用于 iOS 15

let BarButtonItemAppearance = UIBarButtonItem.appearance()
let attributes = [NSAttributedString.Key.font : UIFont(name:"Futura-Medium", size: 14) as Any]
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal)
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)

screenshot

最佳答案

在 iOS 15 上,您似乎必须改用 UINavigationBarAppearance 对象(在我看来,这远非整体改进)

if #available(iOS 15.0, *) {
let navigationAppearance = UINavigationBarAppearance()
navigationAppearance.configureWithDefaultBackground()
let buttonAppearance = UIBarButtonItemAppearance()
buttonAppearance.normal.titleTextAttributes = attributes
buttonAppearance.highlighted.titleTextAttributes = attributes
navigationAppearance.buttonAppearance = buttonAppearance

let appearance = UINavigationBar.appearance()
appearance.standardAppearance = navigationAppearance
appearance.scrollEdgeAppearance = navigationAppearance
} else {
let appearance = UIBarButtonItem.appearance()
appearance.setTitleTextAttributes(attributes, for: .normal)
appearance.setTitleTextAttributes(attributes, for: .highlighted)
}

关于ios - 设置 UIBarButtonItem.appearance() 在 iOS 15 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69356798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com