Set Done Button Colour on SFSafariViewController

99封情书 提交于 2019-12-12 12:38:59

问题


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:

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.


回答1:


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



回答2:


Try setPreferredControlTintColor to set tint color of Done button



来源:https://stackoverflow.com/questions/33482943/set-done-button-colour-on-sfsafariviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!