Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController displaying a black bar

Tags:

ios

swift

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?

like image 545
Fenda Avatar asked Nov 30 '22 18:11

Fenda


1 Answers

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()
}
like image 141
Albert Bori Avatar answered Dec 09 '22 17:12

Albert Bori