6

I see a white divider between the navigation bars in a UISplitviewController on iOS7. I couldn't find a way to change that to black. I changed the backgroundColor of the splitViewController's view to black but no luck.

Screenshot: http://cl.ly/SCcu

Chaitanya
  • 61
  • 1
  • 2

6 Answers6

6

As long as your screen is in Landscape, you can use this as a workaround:

    UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 1, 64)];
    [coverView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"black_pixel.png"]]];
    [splitViewController.view addSubview:coverView];
FeltMarker
  • 510
  • 3
  • 8
  • 1
    This is the only one that allows me to change the divider colour to several different colours while navigating back and forth between table views. Instead of using a 'black pixel' I just set the background colour of the 'coverView'. – Brad G May 27 '14 at 18:06
5

Under the hood, there is a UILayoutContainerView at the top of the screen, below the master and detail views. To change the separator color between nav bars, you only need to change the background color of that view.

In Swift, in your subclass of SplitViewController, try following:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    if let potentialSeparatorView = view.subviews.first as? UIView {
        if round(potentialSeparatorView.bounds.height) == 64 {
            potentialSeparatorView.backgroundColor = UIColor(red:0.20, green:0.55, blue:0.83, alpha:1)
        }
    }
}
Xhacker Liu
  • 1,578
  • 1
  • 16
  • 25
  • Accessing the subviews of a class you do not own is unsafe and something you should never ever do in a shipping app. As is comparing a floating point value to a specific value (that is without some kind of epsilon), as it is highly unreliable. In short: Don't do this. Simply don't. Neither of those. – Regexident Sep 16 '15 at 08:21
  • @Regexident Thank you for your warning. Can you elaborate more about why it’s unsafe to access view.subviews[0] in this case? For comparing floating point, I know it’s not accurate, but I’m not launching a nuclear bumb. If it failed, the background color wouldn’t be changed, that’s it. – Xhacker Liu Sep 16 '15 at 17:42
  • Because the class' owner could change the view hierarchy any time (and Apple often does, obviously). Generally one should never rely on implementation details of an unowned class (if at all). And your `height == 64` fails as soon as Apple changes the view's dimensions or calculates the height differently due to potential rounding errors. – Regexident Sep 16 '15 at 17:47
  • @Regexident Yeah but you know, none of the existing answers works except mine. How to change the separator color is totally undocumented, the only way to do that is some kind of dirty hack. Also I’ve made some changes regarding reliability. – Xhacker Liu Sep 16 '15 at 17:57
  • One can choose to build resilient/safe apps or "merely working" apps. I go for the former whenever I can. Apple might e.g. choose to at some point add a `UIResponder` subclass (that's API-compatible to UIView, yet not a subclass of UIView) as a "subview" to said view. Who knows. They can do whatever they please. It's their class after all. As soon as they do so bad things will happen to your forced cast to `UIView`. `fatalError`-level bad things. You want your code to be predictable. Relying on implementation details is not. – Regexident Sep 16 '15 at 18:44
1

Put your UISplitViewController in additional ViewController with Container View like this:

screenshot

Then hide UINavigationBars in master and detail viewControllers, and you'll have only one UINavigationBar without a white line in additional UIViewController.

screenshot

Styx
  • 9,863
  • 8
  • 43
  • 53
0

Try this:

if ( floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 ) {
    splitViewController.view.backgroundColor = [UIColor blackColor];
}
Steven Grosmark
  • 1,275
  • 1
  • 12
  • 15
0

use

splitViewController?.view.backgroundColor = UIColor.clear

in your tableviewcontroller (master viewcontroller), you can set the color you want as well.

JackyW
  • 345
  • 2
  • 11
-1

You can do the following to get rid of that white line:

self.splitViewController.view.backgroundColor = [UIColor blackColor];
for (UIView *subView in self.splitViewController.view.subviews) {
    subView.backgroundColor = [UIColor blackColor];
} 

for a custom way to get the splitViewController if you don't have direct access to it:

UIViewController *_splitViewController = self.parentViewController;
while (![_splitViewController isKindOfClass:[UISplitViewController class]]) {
    _splitViewController = _splitViewController.parentViewController;
}
_splitViewController.view.backgroundColor = [UIColor blackColor];
for (UIView *subView in ((UISplitViewController *)_splitViewController).view.subviews) {
    subView.backgroundColor = [UIColor blackColor];
}