4

I have a UIPageViewController set up to display pages of UITableViewController content. The functionality is working just fine, but the table is hidden at the top and there is a strange black bar at the bottom.

black bar

So the first thing I did was go to the storyboard and change the settings for my UIPageViewController as shown below.

settings

The resulting view renders like this:

black bar2

Ideally I would like the pager background to be translucent so that you can see the table below it. Also, although the top of the table is now visible, I don't like how the background has changed to a weird grey/translucent effect. Any suggestions on how to fix?

Fenda
  • 1,385
  • 3
  • 14
  • 24

2 Answers2

18

The color of the UIPageControl is already clear. So, what you're seeing is the black background of the UIPageViewController peeking through. The problem is that the UIPageViewController restricts the size of the view controller to not extend beneath the UIPageControl.

Add this following code to your UIPageViewController class to allow your viewController to extend underneath the UIPageControl:

override func viewDidLayoutSubviews() {
    //corrects scrollview frame to allow for full-screen view controller pages
    for subView in self.view.subviews {
        if subView is UIScrollView {
            subView.frame = self.view.bounds
        }
    }
    super.viewDidLayoutSubviews()
}
TMS
  • 1,201
  • 1
  • 13
  • 20
Albert Bori
  • 9,832
  • 10
  • 51
  • 78
1

Use the UIAppearance proxy to customize the colors of UIPageControl, including the background color.

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor blueColor];

To get rid of translucency of the navigation bar use:

[self.navigationController.navigationBar setTranslucent:NO]
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • It looks like the `UIPageControl` is transparent by default. I did try setting the backgroundColor to transparent and that didn't help. – Fenda Jan 22 '15 at 18:46
  • 1
    Turns out its the `UIPageViewController` view background color that is showing. However, I want the table that is displayed inside the pageviewcontroller to be displayed beneath the page control. – Fenda Jan 22 '15 at 18:47