How to Put the Uipagecontrol Element on Top of the Sliding Pages Within a Uipageviewcontroller

How to put the UIPageControl element on top of the sliding pages within a UIPageViewController?

After further investigation and searching I found a solution, also on stackoverflow.

The key is the following message to send to a custom UIPageControl element:

[self.view bringSubviewToFront:self.pageControl];

The AppCoda tutorial is the foundation for this solution:

Add a UIPageControl element on top of the RootViewController - the view controller with the arrow.

Create a related IBOutlet element in your ViewController.m.

In the viewDidLoad method you should then add the following code as the last method you call after adding all subviews.

[self.view bringSubviewToFront:self.pageControl];

To assign the current page based on the pageIndex of the current content view you can add the following to the UIPageViewControllerDataSource methods:

- (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
// ...
index--;
[self.pageControl setCurrentPage:index];

return [self viewControllerAtIndex:index];
}

- (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
// ...
index++;
[self.pageControl setCurrentPage:index];

// ...
return [self viewControllerAtIndex:index];
}

How fix position of UIPageControl ? Fix it always on top when page is changing with PageViewController?

You can achieve this using a container view. Rather than making the UIPageViewController the rootViewController of your UINavigationController, add an intermediate UIViewController that has a container view subview, and add the UIPageControl as a sibling.

You should remove the UIPageControl from your sub view controllers.

You'll need to add some way of propagating page updates back to the UIPageControl - a delegate protocol or closures will work nicely for this.

Sample Image

Positioning a UIPageControl on a UIViewController with respect to the position of a UIView on it's subViewController.

so I found a simple answer....

just add a new UIImageView to the SuperView and set similar constraints so that it obeys the same scaling laws as the UIImageView in the subview. Then use layout constraints to anchor the page indicator to the bottom of the new UIIMageView.

see screenshot.

Sample Image

UIPageViewController and UIPageControl transparent background color - iOS

Okay I've found the solution:

  1. Set a background image on the UIPageViewController.

UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_backgroung"]];
imageView1.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[view addSubview:imageView1];

// Create page view controller
self.pageViewController = [self.storyboard

instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.view.backgroundColor = [UIColor clearColor];
[self.pageViewController.view insertSubview:view atIndex:0];

  1. For your PageViewController viewControllers , choose a PNG Image with graphics or whatever you want, but make sure the background is transparent.
  2. Set your UIPageControl's background as transparent in appDelegate.m

    UIPageControl *pageControl = [UIPageControl appearance];
    pageControl.pageIndicatorTintColor = [UIColor whisperWhite];
    pageControl.currentPageIndicatorTintColor = [UIColor whisperDarkGray];
    pageControl.backgroundColor = [UIColor clearColor];

Now run and your UIPageViewController will look like this, (notice the background static and only the text is moving, as we swipe from right to left):
Sample Image

UIPageControl shifted the image over it (instead of being on top of it)

This following setting was missing on my custom UIViewController:

viewController.automaticallyAdjustsScrollViewInsets = NO;


Related Topics



Leave a reply



Submit