I have a question about implementing a custom scrollable tab bar at the top of the screen in an iOS app. I am looking for a a tab bar very similar to the vevo app (pictured
Basically, you'd do something like the following:
@class CustomTabBar;
@protocol CustomTabBarDatasource
- (int)numberOfElementsInCustomTabBar:(CustomTabBar *)bar;
- (NSString *)titleForTabAtIndex:(int)index inCustomTabBar:(CustomTabBar *)bar;
@end
@protocol CustomTabBarDelegate
- (void)customTabBar:(CustomTabBar *)bar activatedTabAtIndex:(int)index;
@end
@interface CustomTabBar : UIView
@property (weak) id dataSource;
@property (weak) id delegate;
@end
@interface YourViewController : UIViewController {
CustomTabBar *myTabBar;
}
@end
@interface YourViewController (TabBarDataSource)
@end
@interface YourViewController (TabBarDelegate)
@end
The implementation for your CustomTabBar
would include a UIScrollView
and a set of UIButton
s, whose title you would retrieve from the dataSource
. When a button is fired, you'd call the delegate
's customTabBar:activatedTabAtIndex:
method. Your YourViewController
would change its content when the delegate method fires.