以编程方式创建 UIPageControl 时出现问题?
// 初始化页面控件
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(110,5,100,100);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
我正在尝试以编程方式创建 UIPageControl
。我创建了新的基于视图的应用程序。其中,我在 ViewControllers viewDidLoad
中编写了这段代码,但它没有创建页面控件。当我在控制台中看到 viewdidload 被调用多次时。
// Init Page Control
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(110,5,100,100);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
I'm trying to create UIPageControl
programmatically. I created new view based app. In which, i have written this code in ViewControllers viewDidLoad
, but its not creating page control. When i see in console viewdidload is called many times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
LMAO 因为这个原因我也遇到了同样的问题:)
如果您仍然遇到这个问题,或者其他人会遇到这个问题,请尝试设置背景颜色,就像
有趣的是,页面控件的默认颜色设置使其很难在 ie 清晰的白色视图上注意到:)
LMAO with this one cause I just had the same problem :)
if you still got this problem or any one else will struggle with this try setting background colour simply like
the funny thing is that page controls' default colour settings make it difficult to notice on i.e. clear white view :)
在此代码行之前添加一个..
愿此代码对您有所帮助..
Before this code line add one more..
May this one help you..
我在以编程方式构建视图时遇到了问题,发现最好的方法是在
Init
方法中构建一次它们,而不是在ViewDidLoad
方法中构建它们。I've had issues with building views programmatically, and found that the best way is to build them once in the
Init
method, not in theViewDidLoad
method.如果您在白色背景上添加 pageControl,它将不可见。添加临时边框只是为了确保它在那里
如果它在那里,调整色调颜色
如果它不在那里,你可能做错了什么,它应该是这样的:
当然,你还需要将它与相应的scrollView链接/相应的页面视图
if you are adding pageControl on white background it will not be visible. Add temporary border just to make sure it is there
If it is there, adjust tint colors
If it is not there, you are probably doing something wrong, it should be something like this:
Of course, you also need to link it with respective scrollView / pageView accordingly