当在 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
}
但是,“完成”按钮和网站名称的颜色仍然是绿色。
我还尝试对应用程序委托(delegate)中的对象进行覆盖。它们都不起作用。
应用程序委托(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 本身中设置 View 的色调,但它不会为导航栏着色。
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 Controller
//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
方法中
再次将按钮颜色设为全局
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//resetting your button color
UIButton.appearance().tintColor = UIColor.green
}
关于ios - 在 AppDelegate 中设置 UIButton 外观时如何更改 SafariViewController 中导航栏的色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40323858/