我想以编程方式将UIPageControl项添加到我的视图Controller中。 self.view属性包含具有以下属性的UIScrollView:
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;
到目前为止一切顺利。现在我想添加一个PageControl元素(稍后几行):
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
使用@property和@synthesize合成pageControl元素。但是,即使我添加[self.view addSubview:pageControl],这也不会显示任何内容;
为什么这不起作用?
答案 0 :(得分:35)
感谢Nimrod的评论,我有正确的想法,这是它的工作原理(现在我的版本失败了,显而易见):)
// Init Page Control
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(x, y, xx, yy);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];