4

I am using the SFSafariViewController to access a website called from a UITableViewController. Because my app has a very light feel attached to it, I have added the following line of code in the AppDelegate:

self.window.tintColor = [UIColor whiteColor];

When running the SFSafariViewController, I get the following:

enter image description here

Is there anyway I can change the colour of the Done button to Blue (as per default)?

I've tried the following when calling the SFSafariViewController but to no effect:

        [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];
        }];

Neither of those work.

I could of course leave the app as default and take out the white setting from the AppDelegate, but I want this approach within the app because Blue just stands out too much with custom themes.

Any guidance on this would be really appreciated.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

2 Answers2

4

You can change bar colours globally using appearance proxy:

try

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

else try

  [self presentViewController:safariVC animated:YES completion:^{

         [safariVC.navigationBar setTintColor:[UIColor blueColor]];
    }];

else try

in AppDelegate.m in the function:

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

I've entered the following code:

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

or add in your ViewDidLoad

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

Swift

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

else try this

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

or do like

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

or finally try this

  self.navigationController.navigationBar.tintColor = UIColor.whiteColor()
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • see this link may be helps with you http://stackoverflow.com/questions/19368122/cannot-set-text-color-of-send-and-cancel-buttons-in-the-mail-composer-when-prese – Anbu.Karthik Nov 02 '15 at 17:35
  • Thanks @Anbu - that's very helpful. Unfortunately, I just couldn't get this working, no matter what I tried from your answer, the link and any other answers. It just wouldn't show up as Blue in the SFSafariViewController. Do you have any further thoughts? – amitsbajaj Nov 03 '15 at 12:37
  • thats is the way man , I submit my answer in all methods, else check in new/old Xcode version once – Anbu.Karthik Nov 03 '15 at 12:43
  • Do you have it working on a device/simulator? I have self.window.tintColor = [UIColor whiteColor]; in the AppDelegate and I think that's overriding everything. That's important for me because I want every back button (Navigation Controller) to be white, but I just can't get the blue to appear. – amitsbajaj Nov 03 '15 at 12:55
  • Cool, I got it man. I removed the self.window.tintColor = [UIColor whiteColor]; from the AppDelegate and it defaults back to Blue and in each ViewController, I am adding [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; to the viewDidLoad and it works. Thanks for your help on this man! I appreciate it! – amitsbajaj Nov 03 '15 at 13:01
3

Try setPreferredControlTintColor to set tint color of Done button

Chuong Tran
  • 3,131
  • 17
  • 25
  • 1
    You should really add some explanation as to why this should work - you can also add code as well as the comments in the code itself - in its current form, it does not provide any explanation which can help the rest of the community to understand what you did to solve/answer the question. This is especially important for an older question and the questions that already have answers. – ishmaelMakitla Oct 04 '16 at 09:42
  • It's quite simple really. `let svc = SFSafariViewController(url: URL) svc.preferredBarTintColor = .black svc.preferredControlTintColor = .yellow` The first one colours the bar the second the controls' colours. – yuzer Oct 26 '17 at 22:16
  • It dose save my time, and it should be the correct answer! – mrfour Apr 06 '18 at 08:28