【发布时间】:2016-10-29 21:29:38
【问题描述】:
当UIButton.appearance() 在AppDelegate 中设置时,我正在尝试更改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 视图控制器本身中设置视图的色调,但它不会为导航栏着色。
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 上发布了一个示例项目。
任何帮助将不胜感激。谢谢。
(选择颜色用于测试目的。)
【问题讨论】:
-
@Adrian 注意以“SFSafariViewController”开头的部分。
-
@MatthewFrederick 爬回我的洞
-
@Adrian 抱歉,我不是这个意思。
标签: ios swift uibutton uiappearance sfsafariviewcontroller