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.
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.
UIPageViewController and UIPageControl transparent background color - iOS
Okay I've found the solution:
- 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];
- For your PageViewController
viewControllers
, choose a PNG Image with graphics or whatever you want, but make sure the background is transparent. Set your
UIPageControl
's background as transparent inappDelegate.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):
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
Uitableview Auto Resizing Row Constraint Breaking Mysteriously on iPhone 6Plus
Mkmapview Show Incorrectly Saved Region
Are View Controllers with Nib Files Broken in iOS 8 Beta 5
Sending a Private Message to Your Friends via Facebook iOS Sdk
Why Is This Code Not Recognising the Nsstring as Being Equal
Datefromstring Returns Nil for Some Values
Async Request Does Not Enter Completion Block
Switch Universal App to iPhone Only App
Convert Request Function to Generic Type
What Is MACh-O Type Should I Use It in My iOS Objective-C Project
Swift - How to Use 'Shouldchangetextinrange' with Firebase for Real Time Searching
Does Mkannotationview Buffer Its Input Queue
Using Mdm to Configure an Enterprise App via Nsuserdefaults
Using Cabasicanimation to Rotate a Uiimageview More Than Once