【问题标题】:Set Done Button Colour on SFSafariViewController在 SFSafariViewController 上设置完成按钮颜色
【发布时间】:2015-11-02 16:59:35
【问题描述】:

我正在使用SFSafariViewController 访问从UITableViewController 调用的网站。因为我的应用有一种很轻的感觉,所以我在AppDelegate中添加了以下代码行:

self.window.tintColor = [UIColor whiteColor];

运行SFSafariViewController 时,我得到以下信息:

无论如何我可以将Done 按钮的颜色更改为蓝色(默认情况下)?

我在拨打SFSafariViewController 时尝试了以下方法,但没有效果:

        [self presentViewController:safariVC animated:YES completion:^{
            safariVC.navigationController.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];


        [self presentViewController:safariVC animated:YES completion:^{
            safariVC.navigationController.navigationBar.tintColor = [UIColor blueColor];
        }];

这些都不起作用。

我当然可以将应用程序保留为默认设置并从AppDelegate 中取出白色设置,但我希望在应用程序中使用这种方法,因为蓝色在自定义主题中显得过于突出。

对此的任何指导将不胜感激。

【问题讨论】:

    标签: ios objective-c iphone swift sfsafariviewcontroller


    【解决方案1】:

    您可以使用appearance 代理全局更改条形颜色:

    试试

    [[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
    [[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]];
    

    再试试

      [self presentViewController:safariVC animated:YES completion:^{
    
             [safariVC.navigationBar setTintColor:[UIColor blueColor]];
        }];
    

    再试试

    在 AppDelegate.m 函数中:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    我输入了以下代码:

    //SFSafariViewController
    [[UINavigationBar appearanceWhenContainedIn:[SFSafariViewController class], nil] setBarTintColor:[UIColor blueColor]];
    [[UINavigationBar appearanceWhenContainedIn:[SFSafariViewController class], nil] setTintColor:[UIColor blueColor]];
    

    或添加您的 ViewDidLoad

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; 
    

    斯威夫特

    UINavigationBar.appearance().tintColor = UIColor.blueColor()
    UIBarButtonItem.appearance().tintColor = UIColor.blueColor()
    

    试试这个

    self.presentViewController(safariVC, animated: true, completion: {() -> Void in
    safariVC.navigationBar.tintColor = UIColor.blueColor()
    })
    

    或者喜欢

     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    
         UINavigationBar.appearanceWhenContainedIn(SFSafariViewController.self, nil).barTintColor = UIColor.blueColor()
    UINavigationBar.appearanceWhenContainedIn(SFSafariViewController.self, nil).tintColor = UIColor.blueColor()
    }
    

    或者最后试试这个

      self.navigationController.navigationBar.tintColor = UIColor.whiteColor()
    

    【讨论】:

    • 看到这个链接可能对你有帮助stackoverflow.com/questions/19368122/…
    • 谢谢@Anbu - 这很有帮助。不幸的是,无论我从您的答案、链接和任何其他答案中尝试了什么,我都无法正常工作。它只是不会在 SFSafariViewController 中显示为蓝色。你还有什么想法吗?
    • 这就是人的方式,我以所有方法提交我的答案,否则检查新/旧 Xcode 版本一次
    • 你有它在设备/模拟器上工作吗?我有 self.window.tintColor = [UIColor whiteColor];在 AppDelegate 中,我认为这是压倒一切的。这对我来说很重要,因为我希望每个后退按钮(导航控制器)都是白色的,但我就是无法让蓝色出现。
    • 酷,我明白了。我删除了 self.window.tintColor = [UIColor whiteColor];来自 AppDelegate,它默认返回蓝色,在每个 ViewController 中,我添加 [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];到 viewDidLoad 并且它可以工作。感谢您对这个人的帮助!我很感激!
    【解决方案2】:

    试试 setPreferredControlTintColor 设置完成按钮的色调颜色

    【讨论】:

    • 你真的应该添加一些解释为什么这应该工作 - 你也可以添加代码以及代码本身中的 cmets - 在当前的形式中,它没有提供任何可以帮助的解释社区的其他人了解您为解决/回答问题所做的工作。这对于较早的问题和已经有答案的问题尤其重要。
    • 真的很简单。 let svc = SFSafariViewController(url: URL) svc.preferredBarTintColor = .black svc.preferredControlTintColor = .yellow 第一个为条形着色,第二个为控件的颜色。
    • 它可以节省我的时间,它应该是正确的答案!
    猜你喜欢
    • 2013-08-30
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    相关资源
    最近更新 更多