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

at0kjp5o  于 2022-11-26  发布在  iOS
关注(0)|答案(2)|浏览(247)

我在appDelegate中使用此代码将项目中navigationBar的所有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中的完成按钮也是白色的,我如何改变颜色?

0x6upsns

0x6upsns1#

刚刚使用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
}
qvk1mo1f

qvk1mo1f2#

let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.blue], for: .normal)

相关问题