【问题标题】:custom scrollable tab bar on top iOSiOS顶部的自定义可滚动标签栏
【发布时间】:2014-12-03 08:04:21
【问题描述】:

我有一个关于在 iOS 应用程序的屏幕顶部实现自定义可滚动标签栏的问题。我正在寻找一个与 vevo 应用程序非常相似的标签栏(如下图所示)。我已经检查了这个滚动标签栏(https://github.com/vermontlawyer/JFATabBarController),但是想把它移到顶部,当我编辑源代码时它似乎有问题......我假设我不能使用标准的 tabbarcontroller这但必须制作一个自定义标签栏....对吗?我将如何在屏幕顶部创建自定义滚动标签栏?

非常感谢您的任何反馈!

【问题讨论】:

  • 你说控件“有问题”。你看到了什么“故障”?我在运输应用程序中使用此控件已有十个月了,没有收到任何关于“故障”的投诉。

标签: ios scrollbar tabbar


【解决方案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 和一组UIButtons,您将从dataSource 中检索其标题。当一个按钮被触发时,你会调用delegatecustomTabBar:activatedTabAtIndex: 方法。当委托方法触发时,您的 YourViewController 会更改其内容。

【讨论】:

    【解决方案2】:

    这个项目可能会帮助你:https://github.com/Marxon13/M13InfiniteTabBar 但你需要

    由一个无限的 UITabBar 组成,其中嵌入了一个 UIScrollView ;) 并且可以将它配置为将标签栏放在屏幕顶部。

    希望对你有帮助!

    【讨论】:

    【解决方案3】:

    你可以看看这个库:https://github.com/raihan/ZRScrollableTabBar。简单轻量,可能会对您有所帮助。

    【讨论】:

      【解决方案4】:

      我一直在寻找类似的解决方案,但最终想出了自己的解决方案,并希望与以后可能会看到此问题的任何人分享。

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

      这是在情节提要中使用标准UITabBarController 创建滑动标签栏的超级简单方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-07
        • 1970-01-01
        • 2016-04-02
        • 1970-01-01
        • 2011-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多