0

i want to create a navigation bar in which I have a pageControl as well as the Title in the navigation bar just like the twitter iOS app contains, I got them both by setting the

self.navigationItem.Title = @"Home";

and achieved the PageControl by creating an instance of UIPageControl and setting its centre to the centre of the navigation bar and achieving its navigation detection by using the UINavigationController's Delegate. But the problem is that the pageControl and the title are overlapping each other.. how can I set it like this that the Title should appear on the top of page indicator. Here is the code of the positioning the 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;  }
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Ahsan Ebrahim Khatri
  • 1,807
  • 1
  • 20
  • 27
  • 1
    you can try to create an UIView and add to it UILabel with title and UIPageControl, then add this UIView in navigationBar – Ilario Oct 31 '14 at 09:56

1 Answers1

0

I figured it out, both (the title and the pageControl) were overlapping each other so i just changed the Y-Axis of the pageControl and

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;  }  
Ahsan Ebrahim Khatri
  • 1,807
  • 1
  • 20
  • 27