UIPageController in conjuction with UIPageControl?

只愿长相守 提交于 2019-11-27 23:20:06

问题


I have been using UIPageController to navigate between different controllers. Now I would like to add that dots at the bottom, so user can see on which controller he is at. That is achieved via UIPageControl. Is there easy way to combine those two?


回答1:


From the bottom of UIPageViewController.h (iOS6+) ~

A page indicator will be visible if both methods are implemented, transition style is 'UIPageViewControllerTransitionStyleScroll', and navigation orientation is 'UIPageViewControllerNavigationOrientationHorizontal'. Both methods are called in response to a 'setViewControllers:...' call, but the presentation index is updated automatically in the case of gesture-driven navigation.

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); // The number of items reflected in the page indicator.
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); // The selected item reflected in the page indicator.

Otherwise, I think you need to add a UIPageControl to your UIPageViewController and basically tie them together to keep them in sync...but then you do have to do all the tying manually.




回答2:


If you are using Page Based application template of Xcode then go to Attribute inspector and set Transiton style property to Scroll.

and go to your application AppDelegate.m file and set the tint color for the

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

For the page based Xcode template its already their for iOS 6,iOS 7 just its color is set to white.



来源:https://stackoverflow.com/questions/12916216/uipagecontroller-in-conjuction-with-uipagecontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!