ios - 在 SFSafariViewController 上设置完成按钮颜色

标签 ios objective-c iphone swift sfsafariviewcontroller

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

self.window.tintColor = [UIColor whiteColor];

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

enter image description here

我是否可以将 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 中删除白色设置,但我希望在应用程序中使用这种方法,因为蓝色在自定义主题方面过于突出。

任何关于这方面的指导将不胜感激。

最佳答案

您可以使用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]]; 

swift

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()

关于ios - 在 SFSafariViewController 上设置完成按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482943/

相关文章:

ios - 嵌入在 NavigationItem 中的损坏的 UISearchBar 动画

iphone - 将 admob 添加到我的应用程序时架构 armv7s 的 64 个重复符号

iphone - 如何移动 UITextField 中的清除按钮?

ios - 禁用通知时,未在前台调用 didreceiveremotenotification

iphone - NSData dataWithContentsOfURL 缓存

iphone - [NSManagedObject isEqualToString :]: unrecognized selector sent to instance 0x454a590'

iphone - 在后台使用MPMoviePlayer播放mp3文件

仅当从应用商店安装时,IOS 应用才会崩溃

ios - iOS 中是否提供 Fiber(又名用户模式线程、协作多任务处理)?

iphone - 如何在内部分发具有各种内容的 iphone 应用程序?