custom scrollable tab bar on top iOS

前端 未结 4 1032
灰色年华
灰色年华 2021-01-03 01:04

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

4条回答
  •  悲哀的现实
    2021-01-03 01:41

    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 UIButtons, 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.

提交回复
热议问题