12

I would like to add a UIPageControl item programmatically to my view Controller. The self.view property contains a UIScrollView with the following properties:

scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = 1.0;
scrollView.clipsToBounds = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
self.view = scrollView;

So far so good. Now I wanted to add a PageControl element by adding this (a few lines later):

pageControl.numberOfPages = 2;
pageControl.currentPage = 0;

The pageControl element is synthesized using the @property and @synthesize. However, this does not display anything, even if I add a [self.view addSubview:pageControl];

Any ideas why this is not working?

Robin
  • 8,197
  • 11
  • 45
  • 74
  • 3
    Did you instantiate a new page control a la [[UIPageControl alloc] init...]? @property/@synthesize will not create it for you. – Nimrod Jan 14 '10 at 19:01
  • Thanks, just realized this too. I will post the solution I used. – Robin Jan 14 '10 at 19:06

1 Answers1

36

Thanks to the comment from Nimrod I had the right idea, here is how it worked (rather obvious now that my version failed :))

// Init Page Control
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(x, y, xx, yy);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
Robin
  • 8,197
  • 11
  • 45
  • 74