iPad only part of my app:
All my views use the 'default' background colour or:
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> in my storyboard XML.
I want to try and ascertain the default colour of the root view (the view at the bottom of the stack), which is:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
The reason for this, is that I am overlaying a view, initially in the detail or right hand side of the UISplitViewController, so that when the detail view loads for the first time, I can put a splash image in this view. When the user selects a table view cell in the left hand navigation controller of the split view controller, details will appear in the right hand side, and the splash view will get removed.
I want to keep the look and feel of my UI consistent. I cannot use the [UIColor groupTableViewBackgroundColor] for the splash view, because this colour is transparent, and will show through the detail view underneath. The detail view at this point consists of a series of labels & text fields. The text fields are empty, because no table view cell on the left hand side navigation controller of the split view controller has been selected yet.
So, I want to try and set the splash view background colour to the same value as the root view or window of my app.
I want the background colour on the right hand side of the first screenshot to match the background colour on the right hand side of the second screenshot (see above). At the moment, the first screenshot has a background colour of white. I cannot seem to match the gray of the second screenshot by eye, so I need to accurately read this value programmatically. Any ideas?
Can you tell me how I can ascertain this value as a UIColor value?
I have tried doing:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers objectAtIndex:0];
UINavigationController *detailController = [splitViewController.viewControllers objectAtIndex:1];
UINavigationBar *navBar = navigationController.navigationBar;
navBar.tintColor = [UIColor colorWithRed: 0.968627f green:0.584314f blue:0.12549f alpha:1.0f];
UINavigationBar *navBarDetail = detailController.navigationBar;
navBarDetail.tintColor = [UIColor colorWithRed: 0.968627f green:0.584314f blue:0.12549f alpha:1.0f];
UIToolbar *toolBar = navigationController.toolbar;
UIToolbar *toolBarDetail = detailController.toolbar;
NSLog(@"rootviewcontrollerColor: %@",self.window.backgroundColor);
splitViewController.delegate = (id)detailController.topViewController;
}
else{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UINavigationBar *navBar = navController.navigationBar;
navBar.tintColor = [UIColor colorWithRed: 0.968627f green:0.584314f blue:0.12549f alpha:1.0f];
UIToolbar *toolBar = navController.toolbar;
}
return YES;
}
The output from the NSLog is:
2016-11-03 14:06:49.610 Yoga Therapy[96158:19a03] rootviewcontrollerColor: (null)
UPDATE:
When I try:
NSLog(@"rootviewcontrollerColor: %@",self.window.rootViewController.view.backgroundColor);
I get:
UIDeviceWhiteColorSpace 0 1
How can I convert this into UIColor?
UPDATE:
Let me try & explain this another way. Imagine creating an app that has a single UIView, with the default background colour [groupTableViewBackgroundColor], as the root controller. When you run the code in the simulator, the iPad will be filled with a gray colour. What is the RGB value of this colour? The closest word I can think of, to describe this colour is the 'System window colour'...
CGColorRef colorRef = self.window.rootViewController.view.backgroundColor.CGColor;
NSString *colorString = [CIColor colorWithCGColor:colorRef].stringRepresentation;
NSLog(@"colorString = %@", colorString);
Output: