Reputation: 974
I have uislider with 6 tabs at the top please see the .
Now i want to get the tab at which the slider is pointing. if we move the slider.
All the tabs can be rearraged by dragging and placing them so if tab1 moves to position of tab5 and slider is at tab5 (second last position)which is new position for tab1 it should show tab1 values not tab5 values.
- (void)addTab:(UIViewController *)viewController {
if ([self.delegate respondsToSelector:@selector(willShowTab:)]) {
[self.delegate willShowTab:viewController];
}
if (![self.childViewControllers containsObject:viewController] && self.count < self.maxCount - 1) {
[self addChildViewController:viewController];
viewController.view.frame = _contentFrame;
if (_toobarVisible)
[self.toolbar setItems:viewController.toolbarItems animated:YES];
// Add tab selects automatically the new tab
[UIView transitionWithView:self.view
duration:kAddTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView addTab:viewController.title];
if (self.currentViewController) {
[self.currentViewController viewWillDisappear:YES];
[self.currentViewController.view removeFromSuperview];
[self.currentViewController viewDidDisappear:YES];
}
[self.view addSubview:viewController.view];
}
completion:^(BOOL finished){
[viewController didMoveToParentViewController:self];
_currentViewController = viewController;
}];
}
}
Please provide me snippet code.
Appreciate your help.
Thanks,
Upvotes: 0
Views: 185
Reputation: 17732
Ideally, if all of your tabs are the same width, then you just need to figure out which section of the total width the slider is currently positioned at, and select the tab at that index. Otherwise, you would have to iterate through the tabs to find their horizontal bounds to figure out which one the slider is selecting
Upvotes: 1