以编程方式创建 UIPageControl 时出现问题?

发布于 2024-11-06 10:14:26 字数 410 浏览 5 评论 0原文

// 初始化页面控件

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寒冷纷飞旳雪 2024-11-13 10:14:26

LMAO 因为这个原因我也遇到了同样的问题:)
如果您仍然遇到这个问题,或者其他人会遇到这个问题,请尝试设置背景颜色,就像

pageControl.backgroundColor = [UIColor redColor];

有趣的是,页面控件的默认颜色设置使其很难在 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

pageControl.backgroundColor = [UIColor redColor];

the funny thing is that page controls' default colour settings make it difficult to notice on i.e. clear white view :)

痴骨ら 2024-11-13 10:14:26
[self.view addSubview:pageControl];

在此代码行之前添加一个..

[self.view bringSubviewToFront:pageControl];

愿此代码对您有所帮助..

[self.view addSubview:pageControl];

Before this code line add one more..

[self.view bringSubviewToFront:pageControl];

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 the ViewDidLoad method.

留一抹残留的笑 2024-11-13 10:14:26

如果您在白色背景上添加 pageControl,它将不可见。添加临时边框只是为了确保它在那里

    pageControl.layer.borderWidth = 0.5;

如果它在那里,调整色调颜色

    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.blackColor();

如果它不在那里,你可能做错了什么,它应该是这样的:

    var pageControl = UIPageControl(frame: CGRectMake(135, 230, 50, 20))
    pageControl.numberOfPages = 2;
    pageControl.currentPage = 0;
    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.greenColor();
    self.view.addSubview(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

    pageControl.layer.borderWidth = 0.5;

If it is there, adjust tint colors

    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.blackColor();

If it is not there, you are probably doing something wrong, it should be something like this:

    var pageControl = UIPageControl(frame: CGRectMake(135, 230, 50, 20))
    pageControl.numberOfPages = 2;
    pageControl.currentPage = 0;
    pageControl.pageIndicatorTintColor = UIColor.grayColor();
    pageControl.currentPageIndicatorTintColor = UIColor.greenColor();
    self.view.addSubview(pageControl);

Of course, you also need to link it with respective scrollView / pageView accordingly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文