UIPageViewController page control background color

后端 未结 9 1239
一个人的身影
一个人的身影 2020-12-13 00:23

i\'m using UIPageViewController in my app and it\'s working fine. however, it\'s page control which has been added automatically has a black background which is hiding the c

9条回答
  •  时光说笑
    2020-12-13 00:39

    You can use appearance to change the color of UIPageControl as otherwise it is not accessible. Try doing it in your AppDelegate's didFinishLaunchingWithOptions function as given below.

    - (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;
    }
    

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

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

    Only UIPageControl objects contained in the MyViewController are going to get this style.

    EDIT: The black background around UIPageControl at the bottom of your screen 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
    }
    

提交回复
热议问题