gpt4 book ai didi

ios - 在 AppDelegate 中设置 UIButton 外观时如何更改 SafariViewController 中导航栏的色调

转载 作者:可可西里 更新时间:2023-11-01 00:49:57 25 4
gpt4 key购买 nike

当在 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 中的对象。它们都不起作用。

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 本身中设置 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com