自定义可滚动的iOS顶部标签栏

6
我有一个问题,关于在iOS应用程序顶部实现自定义可滚动标签栏。我正在寻找与vevo应用程序非常相似的选项卡栏(如下图所示)。我查看了这个滚动选项卡栏(https://github.com/vermontlawyer/JFATabBarController),但是想要将其移动到顶部,当我编辑源代码时,它似乎存在一些故障... 我假设我不能使用标准的选项卡控制器,而是必须制作一个自定义的选项卡栏 ... 是这样吗?如何创建一个位于屏幕顶部的自定义滚动选项卡栏?谢谢您的任何反馈!
感谢您的回复! vevo tab screen 1 vevo tab screen 2

你说这个控件有“故障”。你看到了哪些“故障”?我在一个运输应用程序中使用了这个控件十个月,没有收到任何关于“故障”的投诉。 - Josh Adams
4个回答

7
这个项目可能会对您有所帮助:https://github.com/Marxon13/M13InfiniteTabBar,但您需要一个包含UIScrollView的无限UITabBar;并且可以配置将选项卡栏放在屏幕顶部。

enter image description here

希望能够帮到您!


@AnkitGupta 我可以访问。你能在这里试试吗?https://github.com/Marxon13?tab=repositories - Carlos Jiménez

1
基本上,您需要执行以下操作:
@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

您的CustomTabBar的实现将包括一个UIScrollView和一组UIButton,其标题将从dataSource中检索。当按钮被触发时,您将调用delegatecustomTabBar:activatedTabAtIndex:方法。当委托方法触发时,您的YourViewController将更改其内容。

0

我曾经在寻找类似的解决方案,但最终自己想出了一个并希望与任何可能在以后查看此内容的人分享。

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

这是一种超级简单的方法,在你的Storyboard中使用标准的UITabBarController创建一个滑动选项卡栏。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接