在 AppDelegate 中设置 UIButton 外观时如何更改 SafariViewController 中导航栏的色调
How to change tint of navigation bar in SafariViewController when setting UIButton appearance in AppDelegate
当 AppDelegate
中设置了 UIButton.appearance()
时,我正在尝试更改 SFSafariViewController
中导航栏的色调。
例如:
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Here is the global setting that I want to override in the
SafariViewController
UIButton.appearance().tintColor = UIColor.green
}
SFSafariViewController
override func viewDidLoad() {
super.viewDidLoad()
// This will change the toolbar tint but not the Done button or the
website name in the "navigation" section
preferredControlTintColor = UIColor.white
}
但是,“完成”按钮和网站名称的颜色仍然是绿色。
我还尝试在 App Delegate 中覆盖对象。 None 他们工作了。
App Delegate(也在didFinishLaunchingWithOptions
)
// These are attempts to override the tint set above. None seem to work.
UIButton.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
UIBarButtonItem.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
UINavigationBar.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
我还尝试在 Safari View Controller 本身中设置视图的色调,但它不会为导航栏着色。
SFSafariViewController(也在viewDidLoad
)
// This can be seen by bringing up an alert like in a peek
view.tintColor = UIColor.purple
这是在 Swift 3.0 中编写并在 Xcode 8.1.
中测试的
我已经在 github 上发布了一个示例项目。
如有任何帮助,我们将不胜感激。谢谢。
(选择颜色用于测试目的。)
我认为我找到的唯一方法是在适当的位置使用您在 AppDelegate
中编写的相同代码。
关于展示 safari 控制器
//Just before presenting the Safari Controller, change the color to red. It will make the Done button color to red.
UIButton.appearance().tintColor = UIColor.red
let controller = StyledSafariViewController(url: appleUrl)
present(controller, animated: true, completion: nil)
并且在SafariController的viewWillDisappear
方法中class
再次将按钮颜色设置为全局颜色
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//resetting your button color
UIButton.appearance().tintColor = UIColor.green
}
当 AppDelegate
中设置了 UIButton.appearance()
时,我正在尝试更改 SFSafariViewController
中导航栏的色调。
例如:
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Here is the global setting that I want to override in the
SafariViewController
UIButton.appearance().tintColor = UIColor.green
}
SFSafariViewController
override func viewDidLoad() {
super.viewDidLoad()
// This will change the toolbar tint but not the Done button or the
website name in the "navigation" section
preferredControlTintColor = UIColor.white
}
但是,“完成”按钮和网站名称的颜色仍然是绿色。
我还尝试在 App Delegate 中覆盖对象。 None 他们工作了。
App Delegate(也在didFinishLaunchingWithOptions
)
// These are attempts to override the tint set above. None seem to work.
UIButton.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
UIBarButtonItem.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
UINavigationBar.appearance(whenContainedInInstancesOf: [SFSafariViewController.self]).tintColor = UIColor.white
我还尝试在 Safari View Controller 本身中设置视图的色调,但它不会为导航栏着色。
SFSafariViewController(也在viewDidLoad
)
// This can be seen by bringing up an alert like in a peek
view.tintColor = UIColor.purple
这是在 Swift 3.0 中编写并在 Xcode 8.1.
中测试的我已经在 github 上发布了一个示例项目。
如有任何帮助,我们将不胜感激。谢谢。
(选择颜色用于测试目的。)
我认为我找到的唯一方法是在适当的位置使用您在 AppDelegate
中编写的相同代码。
关于展示 safari 控制器
//Just before presenting the Safari Controller, change the color to red. It will make the Done button color to red.
UIButton.appearance().tintColor = UIColor.red
let controller = StyledSafariViewController(url: appleUrl)
present(controller, animated: true, completion: nil)
并且在SafariController的viewWillDisappear
方法中class
再次将按钮颜色设置为全局颜色
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//resetting your button color
UIButton.appearance().tintColor = UIColor.green
}