Ios 在AppDelegate中设置UIButton外观时,如何更改SafariViewController中导航栏的色调
当在Ios 在AppDelegate中设置UIButton外观时,如何更改SafariViewController中导航栏的色调,ios,swift,uibutton,uiappearance,sfsafariviewcontroller,Ios,Swift,Uibutton,Uiappearance,Sfsafariviewcontroller,当在AppDelegate中设置ui按钮时,我试图更改SFSafariViewController中导航栏的色调 例如: AppDelegate func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Here is the global settin
AppDelegate
中设置ui按钮时,我试图更改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
}
但是,“完成”按钮和网站名称的颜色仍为绿色
我还尝试在应用程序委托中对对象进行覆盖。他们都没有工作
应用程序代理(也在didfishlaunchingwithoptions
中)
我还尝试在Safari视图控制器本身中设置视图的色调,但它不会对导航栏进行着色
SFSafariViewController(也在viewDidLoad
中)
这是用Swift 3.0编写的,并在Xcode 8.1中测试
我已经在上发布了一个示例项目
任何帮助都将不胜感激。多谢各位
(选择颜色是为了进行测试。)我认为我找到的唯一方法是使用与您在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类的方法
再次使您的按钮颜色为全局
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//resetting your button color
UIButton.appearance().tintColor = UIColor.green
}
@阿德里安注意到以“SFSafariViewController”开头的部分。@MatthewFrederick爬回我的hole@Adrian对不起,这并不是消极的意思。我清楚地提到,通过这段代码,我只能为这个safari控制器更改“完成”按钮的颜色。在Xcode 8.1Cool man上测试,根据要求,它不起作用。这就是为什么被问到?如果它不起作用,那么OP可能不接受答案:)在我发布评论时,她不接受。冷静点,你的代码就像一个专业人员
//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)
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//resetting your button color
UIButton.appearance().tintColor = UIColor.green
}