UIPageControl - How to make the background transparent?

后端 未结 8 2678
無奈伤痛
無奈伤痛 2021-02-18 21:30

I am using UIPageControl and trying to make the background transparent.

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageInd         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-18 22:12

    pageControl.backgroundColor = [UIColor clearColor];
    

    is working but!! than you have to set the backgroundColor of the UIPageViewController also on [UIColor clearColor] and than! you will see the backgroundcolor of the container view.

    - (void)initPageViewController
    {
        _pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
                                                          navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                        options:nil];
    
        UIImageView *imgView= [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        imgView.image = [UIImage imageNamed:@"NiceBGImage"];
        [self.view addSubview:imgView];
    
        self.view.backgroundColor = [UIColor clearColor];
    
        _pageController.view.frame = ({
            CGRect frame = [[UIScreen mainScreen] bounds];
            frame;
        });
    
        _pageController.delegate = self;
        _pageController.dataSource = self;
        _pageController.view.backgroundColor = [UIColor clearColor];
    
        NSArray *controllers = @[_controllers[0]];
    
        [self.pageController setViewControllers:controllers
                                      direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO
                                     completion:nil];
    
        UIPageControl *pageControl = [UIPageControl appearance];
        pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
        pageControl.backgroundColor = [UIColor clearColor];
        pageControl = [UIPageControl appearanceWhenContainedIn:[_pageController class], nil];
    
        [self addChildViewController:_pageController];
        [[self view] addSubview:_pageController.view];
        [self.pageController didMoveToParentViewController:self];
    }
    

提交回复
热议问题