我想创建一个导航栏,其中我有一个pageControl
以及导航栏中的标题,就像 Twitter iOS 应用程序包含的那样,我通过设置
self.navigationItem.Title = @"Home";
并通过创建UIPageControl
实例并将其中心设置为导航栏的中心并使用UINavigationController's
委托实现其导航检测来实现PageControl
。但问题是页面控件和标题相互重叠。我怎样才能这样设置标题应该出现在页面顶部指示器上。这是定位pageControl
的代码。
self.navigationController.delegate = self;
CGSize navBarSize = self.navigationController.navigationBar.bounds.size;
CGPoint origin = CGPointMake( navBarSize.width/2, navBarSize.height/2 );
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(origin.x, origin.y,
0, 0)];
[self.pageControl setNumberOfPages:3];
[self.navigationController.navigationBar addSubview:self.pageControl];
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
int index = [self.navigationController.viewControllers indexOfObject:viewController];
self.pageControl.currentPage = index; }
我想
通了,两者(标题和页面控件(相互重叠,所以我只是更改了页面控件的 Y 轴和
self.navigationController.delegate = self;
CGSize navBarSize = self.navigationController.navigationBar.bounds.size;
CGPoint origin = CGPointMake( navBarSize.width/2, navBarSize.height/2 );
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(origin.x, origin.y+45,
0, 0)]; //Here added 45 to Y and it did the trick
[self.pageControl setNumberOfPages:3];
[self.navigationController.navigationBar addSubview:self.pageControl];
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
int index = [self.navigationController.viewControllers indexOfObject:viewController];
self.pageControl.currentPage = index; }