以编程方式添加 PageControl
我想以编程方式将 UIPageControl 项添加到我的视图控制器中。 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;
pageControl 元素是使用 @property 和 @synthesize 合成的。但是,即使我添加 [self.view addSubview:pageControl]; 这也不会显示任何内容。
有什么想法为什么这不起作用吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Nimrod 的评论,我有了正确的想法,这就是它的工作原理(现在很明显我的版本失败了:))
Thanks to the comment from Nimrod I had the right idea, here is how it worked (rather obvious now that my version failed :))