Change the width of Master in UISplitViewController

前端 未结 16 1624
自闭症患者
自闭症患者 2020-11-28 05:55

The iPad programming guide says that the splitView\'s left pane is fixed to 320 points. But 320 pixels for my master view controller is too much. I would like to reduce it a

相关标签:
16条回答
  • 2020-11-28 06:42

    The storyboard way would be this one, mentioned by @Tim:

    Furthermore, if you want the Master view to always take up a certain percentage of the screen then you can use the Key Path = "preferredPrimaryColumnWidthFraction" instead and set the value to 0.2 (for 20% screen size).

    Please note that the "maximumPrimaryColumnWidth" is set to 320, so if you try the screen percent value of 0.5 (50%) it won't go above 320. You can add a key path for maximumPrimaryColumnWidth if you need to override this.

    0 讨论(0)
  • 2020-11-28 06:42

    Since no one mentioned that this can be done from IB, I want to add this answer. Apparently, you can set "User Defined Runtime Attributes" for the UISplitViewContorller with following details: Key Path:masterColumnWidth Type: Number Value: 250

    0 讨论(0)
  • 2020-11-28 06:43

    Swift 3.0 you use like

    let widthfraction = 2.0 //Your desired value for me 2.0    
    splitViewController?.preferredPrimaryColumnWidthFraction = 0.40
    let minimumWidth = min((splitViewController?.view.bounds.size.width)!,(splitViewController?.view.bounds.height)!)
    splitViewController?.minimumPrimaryColumnWidth = minimumWidth / widthFraction
    splitViewController?.maximumPrimaryColumnWidth = minimumWidth / widthFraction
    let leftNavController = splitViewController?.viewControllers.first as! UINavigationController
    leftNavController.view.frame = CGRect(x: leftNavController.view.frame.origin.x, y: leftNavController.view.frame.origin.y, width: (minimumWidth / widthFraction), height: leftNavController.view.frame.height)
    
    0 讨论(0)
  • 2020-11-28 06:44

    This code work for me:)

    @interface UISplitViewController(myExt) 
    - (void)setNewMasterSize:(float)size; 
    @end

    @implementation UISplitViewController(myExt) - (void)setNewMasterSize:(float)size { _masterColumnWidth = size; } @end

    and use it on each operation with view (like rotation)

    0 讨论(0)
  • 2020-11-28 06:45

    use the following code before assigning to the rootviewcontroller. It works for me with ios7

    [self.splitViewController setValue:[NSNumber numberWithFloat:256.0] forKey:@"_masterColumnWidth"]; self.window.rootViewController = self.splitViewController;

    0 讨论(0)
  • 2020-11-28 06:47

    ViewController.h @property(nonatomic, assign) CGFloat maximumPrimaryColumnWidth NS_AVAILABLE_IOS(8_0);

    ViewController.m

    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    
        if (SYSTEM_VERSION_LESS_THAN(@"10.0")) {
    
        [self setValue:[NSNumber numberWithFloat:200.0]forKey:@"_masterColumnWidth"];
    
        }else{
    
        self.maximumPrimaryColumnWidth = 200;
        self.splitViewController.maximumPrimaryColumnWidth = self.maximumPrimaryColumnWidth;
    
         }
    
    0 讨论(0)
提交回复
热议问题