gpt4 book ai didi

iphone - 以编程方式添加 PageControl

转载 作者:行者123 更新时间:2023-12-03 18:26:25 25 4
gpt4 key购买 nike

我想以编程方式将 UIPageControl 项添加到我的 View 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;

pageControl 元素是使用@property 和@synthesize 合成的。但是,即使我添加 [self.view addSubview:pageControl];,这也不会显示任何内容;

有什么想法为什么这不起作用吗?

最佳答案

感谢 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];

关于iphone - 以编程方式添加 PageControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2066620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com