Is there a problem with the UIPageControl software?

// Initiate the page

UIPageControl *pageControl = [[UIPageControl alloc] init]; 
pageControl.frame = CGRectMake(110,5,100,100); 
pageControl.numberOfPages = 2; 
pageControl.currentPage = 0; 
[self.view addSubview:pageControl];

I am trying to create UIPageControlprogrammatically. I created a new view-based application. In which I wrote this code in ViewControllers viewDidLoad, but did not create control over the page. When I see viewdidload in the console, it is called many times.

+3
source share
4 answers

LMAO with this, because I had the same problem :) if you still have this problem or someone else will struggle with this attempt, set the background color just as

pageControl.backgroundColor = [UIColor redColor];

The funny thing is that the default settings for the default controls make it difficult to notify, i.e. transparent white look :)

+5
source
[self.view addSubview:pageControl];

.

[self.view bringSubviewToFront:pageControl];

.

+2

I had problems representing the building programmatically, and it turned out that the best way is to create them once in a method Init, not in a method ViewDidLoad.

+1
source

If you add pageControl on a white background, it will not be visible. Add a time line to make sure it is.

    pageControl.layer.borderWidth = 0.5;

If it is, adjust the color of the shades.

    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.blackColor();

If not, you are probably doing something wrong, it should be something like this:

    var pageControl = UIPageControl(frame: CGRectMake(135, 230, 50, 20))
    pageControl.numberOfPages = 2;
    pageControl.currentPage = 0;
    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.greenColor();
    self.view.addSubview(pageControl);

Of course, you also need to associate it with the corresponding scrollView / pageView

+1
source

All Articles