Can we customize the page indicator in UIPageViewController?

后端 未结 11 1988
广开言路
广开言路 2020-12-07 17:30

Now it\'s white dots with black background. What about if I want it to be black dots with white backgrounds?

- (NSInteger)presentationCountForPageViewControl         


        
11条回答
  •  时光取名叫无心
    2020-12-07 18:15

    You can use UIAppearance to change the color of UIPageControl. Try this in your AppDelegate's didFinishLaunchingWithOptions function.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UIPageControl *pageControl = [UIPageControl appearance];
        pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
        pageControl.backgroundColor = [UIColor blueColor];
    
        return YES;
    }
    

    EDIT:

    To apply style only to a particular view controller, use appearanceWhenContainedIn instead, as following:

    UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[MyViewController class], nil];
    

    Now, only UIPageControl objects contained in the MyViewController are going to adapt this style.

    Thanks Mike & Shingoo!

    EDIT: If you see black background around UIPageControl at the bottom of your screen, it is due to the background color of your UIPageViewController not UIPageControl. You can change this color as following:

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor blueColor]; //Set it to whatever you like
    }
    

提交回复
热议问题