我在 appDelegate 中使用此代码将项目中导航栏的所有 UIBarButtonItem 的颜色更改为白色
let whiteAttr = [NSAttributedStringKey.font : UIFont(name: "OpenSans", size: 14)! ,NSAttributedStringKey.foregroundColor: UIColor.white]
UIBarButtonItem.appearance().setTitleTextAttributes(whiteAttr, for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes(whiteAttr, for: .highlighted)
但是我的 WKWebView 工具栏的完成按钮也是白色的,我该如何改变颜色?
最佳答案
刚刚使用 iOS 13 中的外观 API 实现了这一点:
let doneButtonAppearance = UIBarButtonItemAppearance()
doneButtonAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.blue]
let toolBarAppearance = UIToolbarAppearance()
toolBarAppearance.doneButtonAppearance = doneButtonAppearance
UIToolbar.appearance().standardAppearance = toolBarAppearance
// Unsure if this is needed
if #available(iOS 15.0, *) {
UIToolbar.appearance().scrollEdgeAppearance = toolBarAppearance
}
关于ios - 在 WKWebView 中更改完成按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47397081/