UIView height before a table section - objective-c

I'm trying to add a view with hight of 50 before table sections, i added the view in interface builder and resize it to 50 and everything looks good in interface builder but once i test it on a device or simulator the view show up with a maximum screen height and it doesn't seem that i can control its height whatever value i use the view takes all the screen hight
How can i force the view height to 50?

Try to use autolayout and set a height constant.

Uncheck "Autoresize Subview" attribute for the parent view in which these view added and check the output. This might solve the problem if some constraint tries to resize the view which was added.

If you want add and UIView before a table section, this view will be before the tableView also. And At least you do by code this view won't be scrolled.
You must change you TabelViewController to a ViewController and adding the tableView Protocols delegate. And no sure but you must have something like that:
#interface TestTableViewController : UITableViewController
And you should be:
#interface TestTableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
Then: In Storyboard add the View and the tableview (Both should have in the same level). Add constrains, connect delegates, and create a IBOutlet for both:
#property (nonatomic,strong) IBOutlet UIView *superHeader;
#property (nonatomic, strong) IBOutlet UITableView *tableView;
With this two outlet if you want you can code to the superHeader disappear when you scrolling until a point, here an example (Remember tableView is a scrollView son).
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y > 100)
{
[UIView animateWithDuration:0.3 animations:^{
// Be carfuly if you are navigationBar (64 ptos) and depens of transparency property
self.tableView.frame = CGRectMake(0, -50, self.view.bounds.size.width, 50);
self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}];
} else if(scrollView.contentOffset.y < 80) {
[UIView animateWithDuration:0.3 animations:^{
// Be carfuly if you are navigationBar (64 ptos) and depens of transparency property
self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 50);
self.tableView.frame = CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height - 50);
}];
}
}

How did you add the view to the UITableView in Interface Builder?
Do you want to have the view displayed before every section?
Then you can add it as a header view for each sections using
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section.
You can specify the height for it using
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
These are both UITableViewDelegate methods.
If you don't want it for every section but rather need one view that is displayed at the top of the TableView, then you can try the tableHeaderView property of UITableView.
You can set any UIView as the header using this property.
See this StackOverflow thread: Adding iOS UITableView HeaderView (not section header)

If you want 50 fixed height then add a constraint to the view "fixed height : 50"
The reason for unchanged frame is the auto layout. SetFrame will work fine when you disable the auto layout.
Hope this will help you

I feel you are not using the prototypecell of tableViewcontroller. Try to add the customisation into that. It may work.

Related

Autolayout - UIView animation from the bottom of the screen

I am using autolayout in my application. I have a UIPicker at the bottom of screen. What I want to do is I want to open UIPicker from the bottom of screen on click of UIButton as shown in image below
I want to know
which kind of constraint I have to set initially
which kind of constraint I have to implement programmatically and how it will be implemented?
How to get back to its original position?
Initially pin top of pickerView to bottom of SuperView and then when you want it to show you can pin bottom of pickerView to bottom of superView.
OR
You can do higher animation by pinning bottom of pickerView to bottom of superView and set height to 0 and when you want to show set height constant to whatEver height is recquired.
follow the below step.
applied this constraint on your object.
after that select vertical space constraint and create IBOutlet for it.
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *TopHeight;
set your desire top margin using below code.it will set new top margin for your object with animation.
self.TopHeight.constant = 400;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
What I have done is, I have set 3 constraint for pickerView as follows.
Then I set outlet of the bottom space to my view.
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
after then on click of botton I write following logic and my work is done.
- (IBAction)showPicker:(id) sender{
self.bottomConstraint.constant = 0;
[self.picker setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
}

Resizing UIButton Frame While Using Size Classes Requires Auto Layout

I have used storyboard to layout a custom cell in a tableview. I have a UI button in this custom cell that has an initial x,y size of 60x7. This UI button (as with all objects in the storyboard) use auto layout with size classes.
When the user clicks on an edit button in the view, I would like to change the size of the UIButton in each cell to be 60x60. Various StackOverflow solutions for changing the UIButton size do something like the following:
CGRect buttonFrame = cell.button1Left.frame;
buttonFrame.size = CGSizeMake(60, 60);
cell.button1Left.frame = buttonFrame;
But the solutions also warn that this will not work unless you turn off auto layout. However, when I try to turn off auto layout for this UIButton in the custom cell, I get the following warning:
This warning scares me. If I disable size classes, will this mess up my layout, disable my segues, and make future changes more difficult? If so, is there any other way to accomplish what I am trying?
Bonus question: is it possible to animate the resizing of the UIButton (i.e. so that it appears to stretch to the larger size)?
Try this:
1) add 2 constraints to your Button in storyboard;
2) create properties for them :
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *btnHeight;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *btnWidth;
3) add action to button click:
- (IBAction)buttonPressed:(id)sender {
UIButton *btn = (UIButton *)sender;
btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
self.btnHeight.constant +=50;
self.btnWidth.constant +=50;
[UIView animateWithDuration: 0.7 animations:^{
[self.view layoutIfNeeded];
}];
}
P.S. If your button is in the center of cell, you need also create top and left constraints and if you make height and width for 50 bigger you need to make top and left for 25 smaller.
I decided that the best solution for me was to create another UIButton that was already the desired size. When the user presses an edit button for the view, I hide the collapsed UIButton that was 60x7. Then I unhide the full size UIButton that is 60x60. To animate the transition so that it looks more natural, I did the following:
[UIView transitionWithView:cell.pencilButtonLeft
duration:0.6
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:NULL
completion:NULL];
cell.pencilButtonLeft.hidden = NO;
As for the warning message when I tried to turn off autosizing, I decided to not turn off autoresizing and not to disable size classes. In reading it closely, I might have been ok as long as I did not have an intention of running the app on a device other than an iPhone. Thanks to #Ptah for the suggestion on the animation.

Set a UIPickerView to bottom of UITableview regardless of scroll position

I'd like to present a UIPickerView snapped to the bottom of a UITableView regardless of where it is scrolled.
Currently I have a UIPickerView added to a UITableView that I present when a button is pressed, but when I scroll the table the UIPickerView goes out of view, and if I'm scrolled out of range of where I've presented it, the UIPickerView appears to have never been called.
Does anyone know how to accomplish this?
Thank
The use of UITableViewController is great unless you need to add subview that don't scroll with the table view. It can't really be done. The solution is to use a UIViewController instead and add your own table view, setup the table view dataSource and delegate protocols and replicate the basic table view controller plumbing.
Once your view controller works like a normal table view controller again, you can now add subviews to the view controller's view that won't scroll with the table.
if u add tableview programatically
SearchtableView.frame = CGRectMake(450, 90, 318, 600);
SearchtableView = [[UITableView alloc] initWithFrame:CGRectMake(623, 90, 400, 400)style:UITableViewStyleGrouped];
[self.view addSubview:SearchtableView];
//belove the tableview//
//Add UIPickerView to the self.view]//
Something told me that there must be a simpler alternative to the answers that I'd been given, and I found a solution.
I decided to find the y coordinate of the scroll point using scrollViewDidScroll: and then animating the UIPickerView to the desired location.
...
[UIView beginAnimations:nil context:NULL];
CGFloat pointY = self.scrollPoint.y;
[self.sortPicker setFrame:CGRectMake(0, pointY + 200, 320, 216)];
[UIView commitAnimations];
...
The UIPickerView will only appear if the scroll has been stopped so it's necessary to implement a method to stop the scroll on touch:
- (void)stopScroll:(UITableView *)tableview
{
CGPoint offset = tableview.contentOffset;
[tableview setContentOffset:offset animated:NO];
}
This will allow you to display and dismiss the UIPickerView at any moment at any given destination.

UIScrollView contentSize not working

I put a UIScrollView in my nib's view, and linked it to a an IBOutlet property.
Now, when I do this in my viewDidLoad method, it seems to have no effect on the contentSize:
self.sv.backgroundColor = [UIColor yellowColor]; // this works
CGSize size = CGSizeMake(1000.0, 1000.0);
[self.sv setContentSize:size]; // this does not
It behaves as if the contentSize was the same as the frame. What's going on?
This started working when I turned off AutoLayout. Why?
I had the same problem. Auto Layout for UIScrollView is messed up.
Work around: Put everything in the UIScrollView into another UIView, and put that UIView as the only child of the UIScrollView. Then you can use Auto Layout.
If things near the end is messed up (the end of whichever direction your UIScrollView scrolls), change the constraint at the end to have the lowest possible priority.
I tried viewWillLayoutSubviews to update scrollView's contentSize, it worked for me.
- (void)viewDidLayoutSubviews
{
[self.bgScrollView setContentSize:CGSizeMake(320, self.view.frame.size.height* 1.5)];
}
Apple Doc
-(void)viewDidLayoutSubviews
Called to notify the view controller that its view has just laid out its subviews.
Discussion
When the bounds change for a view controller’s view, the view adjusts the positions of its subviews and then the system calls this method. However, this method being called does not indicate that the individual layouts of the view’s subviews have been adjusted. Each subview is responsible for adjusting its own layout.
Your view controller can override this method to make changes after the view lays out its subviews. The default implementation of this method does nothing.
The easiest/cleanest way is to set contentSize at viewDidAppear so you negate the effects of autolayout. This doesn't involve adding random views. However relying on load order for an implementation to work may not be the best idea.
Use this code. ScrollView setContentSize should be called async in main thread.
Swift:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
DispatchQueue.main.async {
var contentRect = CGRect.zero
for view in self.scrollView.subviews {
contentRect = contentRect.union(view.frame)
}
self.scrollView.contentSize = contentRect.size
}
}
Objective C:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
dispatch_async(dispatch_get_main_queue(), ^ {
CGRect contentRect = CGRectZero;
for(UIView *view in scrollView.subviews)
contentRect = CGRectUnion(contentRect,view.frame);
scrollView.contentSize = contentRect.size;
});
}
There are two problems here. (1) viewDidLoad is too soon; you have to wait until after layout has taken place. (2) If you want to use autolayout with a scrollview that comes from a nib, then either you must use constraints to completely describe the size of the contentSize (and then you don't set the contentSize in code at all), or, if you want to set it in code, you must prevent the constraints on the scrollview's subviews from dictating the contentSize. It sounds like you would like to do the latter. To do so, you need a UIView that acts as the sole top-level subview of the scrollview, and in code you must set it to not use autolayout, enabling its autoresizingMask and removing its other external constraints. I show an example of how to do that, here:
https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch20p573scrollViewAutoLayout/ch20p573scrollViewAutoLayout/ViewController.m
But notice also the next example, which shows how to use constraints completely, instead of contentSize.
A SUPER easy way to use AutoLayout with UIScrollViews inside Interface Builder:
Step 1: Create a UIScrollView
Step 2: Create a UIView that is a child of your scroll view like so:
-UIScrollView
---UIView
-----Your other content
(We'll call this one contentView).
Step 3: In the size inspector, give this view a height and width (say, 320x700).
Step 4 (using AutoLayout): Create unambiguous constraints from your contentView to its superview (the UIScrollView): connect the 4 edges (top, leading, trailing, bottom), then give it a defined width and height that you want it to scroll too.
For example: If your scroll view spans the entire screen, you could give your content view a width of [device width] and a height of 600; it will then set the content size of the UIScrollView to match.
OR:
Step 4 (not using AutoLayout): Connect both of these new controls to your view controller using IB (ctrl+drag from each control to your view controller's .h #implementation). Let's assume each is called scrollView and contentView, respectively. It should look like this:
#interface YourViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) IBOutlet UIView *contentView;
#end
Step 5 (not using AutoLayout): In the view controller's .h file add (actually, override) the following method:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.scrollView.contentSize = self.contentView.frame.size;
}
You can use this lines of code into your *.m file's
- (void)viewDidLoad{
[scroll setContentSize:CGSizeMake(320, 800)] ;
[scroll setScrollEnabled:TRUE];
[scroll setShowsVerticalScrollIndicator:NO];
[scroll setShowsHorizontalScrollIndicator:YES];
}
for this you need to take an IBOutlet property of UIScrollView into your *.h file this way:
IBOutlet UIScrollView *scroll;
And connect this from Storyboard.
Or,
You can use this method into your *.m file:
-(void)viewDidLayoutSubviews
{
[scroll setContentSize:CGSizeMake(320, self.view.frame.size.height* 1.5)];
// this will pick height automatically from device's height and multiply it with 1.5
}
This both solution works for me in xcode-5, xcode-6, xcode-6.1, xcode-6.2
Setting the contentSize in viewDidAppear is critical.
But I also had a variation of what worked in the 3.5 inch screen, and the 4 inch screen. The 4 inch screen worked, the older one does not. Both iOS 7. Bizarre is an understatement!
I could never get auto layout based on constraints to work. Since my view was already a subclass UIScrollView I solved it by overriding setContentView: and ignoring auto layouts zero height setContentSize: message.
#interface MyView : UIScrollView {}
#end
#implementation MyView
- (void)setContentSize:(CGSize)aSize {
if (aSize.height > 0)
[super setContentSize:aSize];
}
#end
I used to do set up the uiscrollview programmatically UNTIL I watched the following wonderful tutorial, step by step how to get uiscrollview and uiview to work: https://www.youtube.com/watch?v=PgeNPRBrB18
After watching the video you will start liking Interface Builder I am sure.
Vote up
Still not scrolling when dynamic height of labels exceeds view height.
I did what yuf's answer marked as correct above said to do (I added a content view to my scrollview and set the constraints leading, trailing, top bottom, and equal widths from the content view to the scroll view.) but still my view was not scrolling when the internal controls height exceeded the height of the scrollview.
Inside my content view I have an image and 3 labels below it. Each label adjusts their own height dependant on how much text is in them (they are set to word-wrap and numberoflines = 0 to achieve this).
The problem I had was my content view's height was not adjusting with the dynamic height of the labels when they exceeded the height of the scroll view/main view.
To fix this I worded out I needed to set the Bottom Space to Container constraint between my bottom label and the contentview and gave it a value of 40 (chosen arbitrarily to give it a nice margin at the bottom). This now means that my contentview adjusts its height so that there is a space between the bottom of the last label and itself and it scrolls perfectly!
Yay!
Try this out...
add all constraints like you do for UIView (See screenShot of my ViewControler in Storyboard)
Now trick begins. select your last object and select its bottom constraint. (See above screenShot, Instagram button's Bottom Constraint(Yellow line)) and Change the Constant in Size Inspector like in bellow screenshot.
i require Constant=8 but you can change as per your requirements.
this Constant is the Space between That Orange Button's Bottom and the scrollView.
EDIT
Make Sure about your view's hierarchy .
0) ViewController.view (optional)
1) UIScrollView
2) UIView (Rename as "contentView")
3) UIView (this view is your content that will make scrollView scroll)
I finally worked out my own solution to this problem because in my case I couldn't use the view controller's life cycle. Create your own scroll view subclass and use it instead of UIScrollView. This even worked for a scroll view inside a collection view cell.
class MyScrollView:UIScrollView {
var myContentSize:CGSize = CGSize.zero // you must set this yourself
override func layoutSubviews() {
super.layoutSubviews()
contentSize = myContentSize
}
}
My MyScrollView was defined in the nib with a tag of 90. If so this is a good way to set content size in the code in the parent view.
let scrollView = viewWithTag(90) as! MyScrollView
scrollView.myContentSize = ...
If you are using AutoLayout a really easy way to set the contentSize of a UIScrollView is just to add something like this:
CGFloat contentWidth = YOUR_CONTENT_WIDTH;
NSLayoutConstraint *constraintWidth =
[NSLayoutConstraint constraintWithItem:self.scrollView
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.scrollView
attribute:NSLayoutAttributeLeading
multiplier:1
constant:contentWidth];
[self.scrollView addConstraint:constraintWidth];
I got Autolayout to work for paginated scroll views whose pages occupy the full-width of the screen. The pages automatically resize according to the scroll view's size. I haven't tested this for lesser-width scroll views but do comment away if it works--I beleieve it should. Targeted for iOS 9, wrote code in Swift 2, used a mix of IB's and custom code in awakeFromNib.
Steps:
Define a full-screen scroll view.
Inside the scroll view, add a UIView (I called mine contentView) whose top, trailing, bottom, and leading edges to the scroll view are all zero; the height is equal to the scroll view's; but the width is the scroll view's width times the number of pages. If you're doing this visually, you will see your content view extend beyond your scroll view in Inteface Builder.
For every "page" inside the contentView, add Autolayout rules to put them side-by-side each other, but most importantly, give them each a constraint so that their widths are equal to the scroll view's, not the content view's.
Sample code below. embedChildViewController is just my convenience method for adding child VCs--do look at setupLayoutRulesForPages. I have exactly two pages so the function is too simple, but you can expand it to your needs.
In my view controller:
override func loadView() {
self.view = self.customView
}
override func viewDidLoad() {
super.viewDidLoad()
self.embedChildViewController(self.addExpenseVC, toView: self.customView.contentView, fillSuperview: false)
self.embedChildViewController(self.addCategoryVC, toView: self.customView.contentView, fillSuperview: false)
self.customView.setupLayoutRulesForPages(self.addExpenseVC.view, secondPage: self.addCategoryVC.view)
}
My custom view:
class __AMVCView: UIView {
#IBOutlet weak var scrollView: UIScrollView!
#IBOutlet weak var contentView: UIView!
#IBOutlet weak var pageControl: UIPageControl!
override func awakeFromNib() {
super.awakeFromNib()
self.scrollView.pagingEnabled = true
self.scrollView.bounces = true
self.scrollView.showsHorizontalScrollIndicator = false
self.scrollView.showsVerticalScrollIndicator = false
self.pageControl.numberOfPages = 2
self.contentView.backgroundColor = UIColor.blueColor()
self.scrollView.backgroundColor = UIColor.clearColor()
self.backgroundColor = UIColor.blackColor()
}
func setupLayoutRulesForPages(firstPage: UIView, secondPage: UIView) {
guard self.contentView.subviews.contains(firstPage) && self.contentView.subviews.contains(secondPage)
else {
return
}
let rules = [
"H:|-0-[firstPage]-0-[secondPage]-0-|",
"V:|-0-[firstPage]-0-|",
"V:|-0-[secondPage]-0-|"
]
let views = [
"firstPage" : firstPage,
"secondPage" : secondPage
]
let constraints = NSLayoutConstraint.constraintsWithVisualFormatArray(rules, metrics: nil, views: views)
UIView.disableAutoresizingMasksInViews(firstPage, secondPage)
self.addConstraints(constraints)
// Add the width Autolayout rules to the pages.
let widthConstraint = NSLayoutConstraint(item: firstPage, attribute: .Width, relatedBy: .Equal, toItem: self.scrollView, attribute: .Width, multiplier: 1, constant: 0)
self.addConstraint(widthConstraint)
}
}

UISplitViewController: remove divider line

When using UISplitViewController on the iPad there's a black vertical divider line between the root and detail view. Is there any way to remove this line?
Thanks
Excellent answer by #bteapot. I tested this and it works, even gets rid of the line between master/detail nav bars.
You can do this in storyboard by adding the "gutterWidth" key path and the value 0 to the USplitViewController runtime attributes.
Actuly I have some modification to answer of (Dylan)'s answer
in the appDelegate we need to add image in spliteview controller rather then window
self.splitViewController.view.opaque = NO;
imgView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"FullNavBar.png"]];
[imgView setFrame:CGRectMake(0, 0, 1024, 44)];
[[self.splitViewController view] insertSubview:imgView atIndex:0];
[[self.splitViewController view] setBackgroundColor:[UIColor clearColor]];
here self is object of AppDelegate.
now Apply the answer of this thread : iPhoneOS SDK - Remove Corner Rounding from views (iPad problem) answer by (abs)
edit in above post's answer is
-(void) fixRoundedSplitViewCorner {
[self explode:[[UIApplication sharedApplication] keyWindow] level:0];
}
-(void) explode:(id)aView level:(int)level
{
if ([aView isKindOfClass:[UIImageView class]]) {
UIImageView* roundedCornerImage = (UIImageView*)aView;
roundedCornerImage.hidden = YES;
}
if (level < 2) {
for (UIView *subview in [aView subviews]) {
[self explode:subview level:(level + 1)];
}
}
imgView.hidden = FALSE;
}
** make imgView.hidden to FALSE
declare imgView to the AppDelegate.h file**
and dont forget to call this
-(void)didRotateFromInterfaceOrientation:
UIInterfaceOrientation)fromInterfaceOrientation
{
[yourAppDelegate performSelector:#selector(fixRoundedSplitViewCorner)
withObject:NULL afterDelay:0];
}
chintan adatiya answer covers only the corners and the navigation bar, but I found an trick how to cover the line between the Master and the Detail view.
It is not nice but it works like a charm.
First create an image which is 1 px wide and 704 pixels high.
In the didFinishLaunchingWithOptions add the following code:
UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(320, 44, 1, 704)];
[coverView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"divider_cover.png"]]];
[splitViewController.view addSubview:coverView];
And done.
When you want a background image which is continues create 3 images:
Master: width: 320, height: 704
Detail: width: 703, height: 704
Divider:width: 1, height: 704
First post here, hi everyone.
I discovered how to do it accidentally... when I tried to find why I had LOST the divider line. Here's how to hide it, if you're still interested:
1) In your Detail (right-side) view, make sure you have a subview that spans the whole view.
2) Offset this subview view to (-1, 0).
3) Make sure that the Detail View has its "Clip Subviews" option unchecked.
Voilà, enjoy.
You can mostly get rid of it by setting another image behind it in the main window's views. This is from the app delegate didFinishLaunchingWithOptions
// Add the split view controller's view to the window and display.
splitViewController.view.opaque = NO;
splitViewController.view.backgroundColor = [UIColor clearColor];
[window addSubview:splitViewController.view];
[window insertSubview:bgImageView belowSubview:splitViewController.view];
[window makeKeyAndVisible];
But it still leaves two visual artifacts at the top and the bottom that appear to be custom drawn by the splitviewcontroller.
Interestingly, In the app that I'm working on I want a black background color for both views in the UISplitViewController. I'd like to change the color of the divider line to white (so that you can see it). Making both background colors black is one way to get rid of (make invisible) the dividing line but that's probably not a solution for most people.
Tested on iOS10 (probably will work on iOS9 too).
splitviewController.view.backgroundColor = UIColor.white
it removes divider. Apparently divider is just a gap between master and detail container.
I looked around for a while, and came to the conclusion that theres no way to do this, other than to create your own custom split view.
Try the MGSplitViewController by Matt Gammell
http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad
I may be late here, but I DO have a solution that works. It even works for the iOS 8+ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; and seamlessly slides in and out when you press the Full Screen toggle button.
Here is the trick :
first Subclass UISplitViewController.m
In the header add the follwing :
#property (strong, nonatomic) UIView *fakeNavBarBGView;
In the viewDidLoad method add the following code :
CGFloat fakeNavBarWidth = 321; // It is important to have it span the width of the master view + 1 because it will not move when the split view slides it's subviews (master and detail)
CGFloat navbarHeight = self.navigationController.navigationBar.frame.size.height + 20;
self.fakeNavBarBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, fakeNavBarWidth, navbarHeight)];
self.fakeNavBarBGView.backgroundColor = [UIColor redColor];
// Add Fake navbar to back of view
[self.view insertSubview:self.fakeNavBarBGView atIndex:0];
// SplitView Controller
UISplitViewController *splitViewController = self;
DetailViewController *detailVC = [navigationController.viewControllers lastObject];
detailVC.fakeNavBarSubView = self.fakeNavBarBGView;
detailVC.SVView = self.view;
In the DetailViewController.h add the following :
#property (strong, nonatomic) UIView *SVView;
#property (strong, nonatomic) UIView *fakeNavBarSubView;
Now here is the final trick : in the DetailViewController.m, add the following in the viewDidLoad method (called every time you click the Master table) :
[self.SVView sendSubviewToBack:self.fakeNavBarSubView];
[self.SVView bringSubviewToFront:self.view];
Run it and watch the magic ;-)
Private API (can cause App Store rejection):
[splitViewController setValue:#0.0 forKey:#"gutterWidth"];
I did this accidentally by setting the backgroundColor property of the first viewController's view - possibly to clearColor, I don't remember now.
UIManager.put("SplitPaneDivider.draggingColor", new Color(255, 255, 255, 0));