简体   繁体   English

如何获取UIPageControl的大小?

[英]How to get UIPageControl size?

In an UIViewController I have set an UIPageController as a child controller. 在UIViewController中,我已将UIPageController设置为子控制器。
UIPageController displays correctly a Page Control panel at the bottom of the screen. UIPageController在屏幕底部正确显示“页面控制”面板。

My problem is that I want to put images above the Page Control in the UIPageController and for this I would like to get the size of the Page Control panel. 我的问题是我想将图像放在UIPageController中的页面控件上方,为此,我想获取页面控件面板的大小。

How can I get the size of a Page Control panel? 如何获得页面控制面板的大小?

I tried to resize it in the DiceTownAppDelegate but the size doesn't change (changing color works though): 我试图在DiceTownAppDelegate中调整它的大小,但是大小没有变化(尽管更改颜色是可行的):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary   *)launchOptions{
       UIPageControl *pageControl = [UIPageControl appearance];
       pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
       pageControl.currentPageIndicatorTintColor = [UIColor blackColor];

       pageControl.frame = CGRectMake(0, 0, kScreenWidth, kPageControlHeight);

       pageControl.backgroundColor = [UIColor whiteColor];
       return YES;
}

You can this method on your UIPageControl instance: 您可以在UIPageControl实例上使用此方法:

- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount

But this won't work in the AppDelegate's didFinishLaunchingWithOptions , as you won't be able to get the UIPageControl there (it doesn't exist yet). 但这在AppDelegate的didFinishLaunchingWithOptions不起作用,因为您将无法在此获取UIPageControl(尚不存在)。 You probably should do this in your controller's viewDidLoad . 您可能应该在控制器的viewDidLoad执行此操作。 Setting the color does work because in your code you are configuring the appearance proxy (not a specific instance), ie you are telling your app to use this color in all UIPageControls. 设置颜色确实可行,因为在代码中您正在配置外观代理(不是特定实例),即,您要告诉应用程序在所有UIPageControls中使用此颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM