Resize master and detail view controllers in a split view controller?
Asked Answered
C

3

7

I'm working in Xcode 4.2 and am developing an app where I want the menu screen to use a Split View. Really, all I need the Split View Controller for is to split some of the menu options into a left pane and right pane. I want to be able to set custom sizes for the master and detail view controllers, but nothing seems to be working for me. I've tried updating the frame sizes for each view controller with code like:

[self.view setFrame:CGRectMake(0, 0, 768, 502)];

in the viewDidLoad functions, but that doesn't seem to affect anything.

Is there a way to set custom sizes for the master and detail view controllers of a split view controller without instantiating the view controllers in say the AppDelegate.m file? I want to be able to edit each of the view controllers in the storyboard as they are menu screens with a lot of buttons and such.

Caravan answered 16/4, 2012 at 2:38 Comment(0)
S
10

Edit: In iOS 8+, the relative widths can be changed by specifying the minimum/maximumPrimaryColumnWidth properties or the preferredPrimaryColumnFraction.

The below answer is still true for iOS < 8:


You can't change the sizes for a split view controller.

See here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html

"The UISplitViewController class is a container view controller that manages two panes of information. The first pane has a fixed width of 320 points and a height that matches the visible window height. The second pane fills the remaining space."

Sarina answered 16/4, 2012 at 4:10 Comment(2)
Hmm, ok, thanks. Is there any other workaround I could potentially use? All I really need is one view with two vertical panes where I can choose a size for each.Caravan
You can just make a big view with two views, and assign the view of each in code.Sarina
L
4

Use MGSplitViewController. It offers similar API to UIViewController, but offering additional features, such as split position, which is what you need.

Luckett answered 12/5, 2012 at 17:13 Comment(3)
Is there a newer version of this view controller at all? It seems dated and unsupported. It does run on iOS7, however.Digenesis
@Digenesis I am not sure, I kind of stopped following MGSplitViewController and built my own wrapper for UISplitViewController which allowed me to achieve what I needed. To be honest, if I had to do a split view controller now, I'd do a new custom one instead of using MGSplitViewController, as it is really quite easy to accomplish with parent/child view controller containment.Trovillion
Yep — using container views has worked for me alright so far too actually. I didn't use MGSplitViewController in the end either.Digenesis
N
-1
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex;
{

    return proposedMinimumPosition + 238;
}

- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
    return proposedMaximumPosition - 200;
}

before the above delegate method add [splitView addDelegate:self];

Napiform answered 19/6, 2013 at 10:54 Comment(1)
These methods are for Mac, with the NSSplitViewDelegate. The OP didn't specify Mac or iOS app, however they have a tag which says uisplitviewcontroller which is for iOS.Brittle

© 2022 - 2024 — McMap. All rights reserved.