ios - 在 WKWebView 中更改完成按钮的颜色

标签 ios swift uibarbuttonitem wkwebview uitoolbar

我在 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/

相关文章:

ios - 唯一的字符 - 不是键盘上的特殊/数字 - iPhone

iOS:CGImageCreateWith[PNG 或 JPEG]DataProvider 导致段错误

swift - 类层次结构 - 类只能由另一个类调用

ios - 在 iPhone 的导航栏中显示来自栏按钮的弹出窗口

iphone - IOS在keychain中存储多个密码

ios - 如何使用 swift 3 删除按钮的图像

ios - 导航栏上的自定义 UIBarButtonItem 图像偏移

ios - 在文本属性字典中实例化 UIFont 时出错

ios - 快速提取和管理数组元素

ios - 使用 tableviewcontroller 时对导航栏的模糊效果