custom scrollable tab bar on top iOS

≡放荡痞女 提交于 2019-11-30 14:07:53

this project may help you: https://github.com/Marxon13/M13InfiniteTabBar but you need

Consist in a infinite UITabBar with a UIScrollView embedded in it ;) and it can be configure to put the tabbar in top of screen.

Hope it helps!

Basically, you'd do something like the following:

@class CustomTabBar;

@protocol CustomTabBarDatasource <NSObject>
- (int)numberOfElementsInCustomTabBar:(CustomTabBar *)bar;
- (NSString *)titleForTabAtIndex:(int)index inCustomTabBar:(CustomTabBar *)bar;
@end

@protocol CustomTabBarDelegate <NSObject>
- (void)customTabBar:(CustomTabBar *)bar activatedTabAtIndex:(int)index;
@end

@interface CustomTabBar : UIView
@property (weak) id<CustomTabBarDataSource> dataSource;
@property (weak) id<CustomTabBarDelegate> delegate;
@end

@interface YourViewController : UIViewController {
  CustomTabBar *myTabBar;
}
@end

@interface YourViewController (TabBarDataSource) <CustomTabBarDataSource>
@end

@interface YourViewController (TabBarDelegate) <CustomTabBarDelegate>
@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.

You can have a look at this library: https://github.com/raihan/ZRScrollableTabBar. Which is simple and lightweight and may help you.

I was looking for a similar solution, but ended up coming up with my own and wanted to share for anyone that might be looking at this later.

https://github.com/chrismanahan/Simple-Scrolling-Tab-Bar

It's a super simple way to create a sliding tab bar with the standard UITabBarController in your storyboard.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!