Search code examples
iosobjective-cswiftxcode6xcode-storyboard

Views not displaying correctly with storyboard


I created a page based application which already has several views. RootViewController is responsible for setting up the app layout, and it does everything well except for one thing, the view size.

Here's part of what I have

    // Configure the page view controller and add it as a child view controller
    self.pageViewController = UIPageViewController(
        transitionStyle: .Scroll,
        navigationOrientation: .Horizontal,
        options: nil
    );

    self.pageViewController.delegate = self;

    // Setup the initial page
    let startingViewController = self.modelController.viewControllerWithProfileProvider(
        self.profileProviderPreference(),
        storyboard: self.storyboard
    );

    self.pageViewController.setViewControllers(
        [startingViewController as BrowsingViewControllerBase] as [AnyObject],
        direction: UIPageViewControllerNavigationDirection.Forward,
        animated: false,
        completion: { done in }
    );

    self.pageViewController.dataSource = self.modelController;
    self.addChildViewController(self.pageViewController);
    self.view.addSubview(pageViewController.view);

    // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages
    self.pageViewController.view.frame = self.view.bounds;

    // Notify the page view controller that we just moved to it. This is a framework imposition. See the docs.
    self.pageViewController.didMoveToParentViewController(self);

    // Add the page view controller's gesture recognizers to the view controller's view so that the gestures are started more easily.
    self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;

All other code in the controllers handles behaviour, not aspect, so I setup everything else using Storyboard. The viewControllerWithProfileProvider: method is returning the proper view, which gets presented on screen, but not correctly. Here's what I have in storyboard:

enter image description here

I then change the colour and label for the button according to the provider given (ie., Facebook, Twitter, LinkedIn...). But I get this:

enter image description here

Notice how the button is off the screen. I would assume that self.pageViewController.view.frame = self.view.bounds; is the key line for this, but I'm not sure what to use. How can I have my views display correctly?


Solution

  • Control Click the box and drag up and leave from the popup select Top space to top layout. do the same on both right and left side and select leading space and trailing space respectively. Run your app hopefully this helps