Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 导航栏中的pageControl未居中_Ios_Objective C_Iphone_Swift_Uinavigationbar - Fatal编程技术网

Ios 导航栏中的pageControl未居中

Ios 导航栏中的pageControl未居中,ios,objective-c,iphone,swift,uinavigationbar,Ios,Objective C,Iphone,Swift,Uinavigationbar,我已经使用interface builder向标题视图添加了一个pageControl。问题是它根本没有居中。实际上,我可以在leftBarButton文本后添加很多空格,但这并不理想。解决办法是什么 尝试这样做,而不是从故事板添加页面控制器 pageControl = [[UIPageControl alloc] init]; pageControl.frame = CGRectMake(x, y, xx, yy); pageControl.numberOfPages = 2; pageCon

我已经使用interface builder向标题视图添加了一个pageControl。问题是它根本没有居中。实际上,我可以在leftBarButton文本后添加很多空格,但这并不理想。解决办法是什么


尝试这样做,而不是从故事板添加页面控制器

pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(x, y, xx, yy);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
self.navigationItem.titleView = pageControl;

标题视图会自动居中(如果可能的话),因此它可能会被右栏按钮项推到左侧。为了进行调试,您应该在标题视图中添加背景色,以便查看这是否正确。如果这是个问题,你需要把你的标题视图缩小,这样它就不会碰到任何一个按钮


另一种可能性(如果有背景色,您可以看到)是页面控件未在标题视图中居中。如果这就是问题所在,您需要向页面控件添加centerX约束。

我在寻找确切问题的答案时看到了这篇文章。我最终解决了这个问题,在
UIView
中添加了
UIPageControl
,并设置了适当的约束,使其在
UIView
中居中。您可以在故事板中轻松地执行此操作,并将此
UIView
添加到标题视图中。希望这有帮助。

结果是一样的