UIPageViewController page control background color

后端 未结 9 1241
一个人的身影
一个人的身影 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:45

    Add the following code in the UIPageViewController.

    - (void)viewDidLoad {
        [super viewDidLoad];
        [[UIPageControl appearance] setPageIndicatorTintColor: [UIColor grayColor]];
        [[UIPageControl appearance] setCurrentPageIndicatorTintColor: [UIColor whiteColor]];
        [[UIPageControl appearance] setBackgroundColor: [UIColor darkGrayColor]];
    }
    
    0 讨论(0)
  • 2020-12-13 00:45

    Here is the Swift 2+ version of Yas-T's Answer

    //In AppDelegate
    let pageControl = UIPageControl.appearance()
    pageControl.pageIndicatorTintColor = UIColor.lightGrayColor()
    pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
    pageControl.backgroundColor = UIColor.blueColor()
    
    //Or in your ViewController (Only available on IOS 9.0)
    if #available(iOS 9.0, *) {
       let pageControl = UIPageControl.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
       pageControl.pageIndicatorTintColor = UIColor.lightGrayColor()
       pageControl.currentPageIndicatorTintColor = UIColor.darkGrayColor()
    }
    
    0 讨论(0)
  • 2020-12-13 00:50

    Well, I found a working solution. Inside your UIPageViewController, just add this code:

    -(void)viewDidLayoutSubviews
    {
       [super viewDidLayoutSubviews];
    
       for (UIView *view in self.view.subviews)
       {
           if ([view isKindOfClass:UIScrollView.class])
           {
               CGRect frame      = view.frame;
    
               frame.size.height = view.superview.frame.size.height;
    
               view.frame        = frame;
           }
    
           if ([view isKindOfClass:UIPageControl.class])
           {
               CGFloat newHeight    = 22;
    
               CGRect frame         = view.frame;
    
               frame.origin.y      += frame.size.height - newHeight;
               frame.size.height    = newHeight;
    
               view.frame           = frame;
               view.backgroundColor = UIColor.darkGrayColor;
               view.alpha           = 0.3;
           }
       }
    

    }

    0 讨论(0)
提交回复
热议问题