
A powerful and easy to use category view (segmentedcontrol, segmentview, pagingview, pagerview, pagecontrol) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
与其他的同类三方库对比的优点:
如果你在找Swift版本,请点击查看JXSegmentedView
以下均支持上下位置切换: JXCategoryIndicatorLineView、JXCategoryIndicatorImageView、JXCategoryIndicatorBallView、JXCategoryIndicatorTriangleView
| 说明 | Gif |
|---|---|
| 颜色渐变 | ![]() |
| 大小缩放 | ![]() |
| 大小缩放+底部锚点 | ![]() |
| 大小缩放+顶部锚点 | ![]() |
| 大小缩放+字体粗细 | ![]() |
| 大小缩放+点击动画 | ![]() |
| 大小缩放+cell宽度缩放 | ![]() |
| TitleImage_Top | ![]() |
| TitleImage_Left | ![]() |
| TitleImage_Bottom | ![]() |
| TitleImage_Right | ![]() |
| cell图文混用 | ![]() |
| Image | ![]() |
| 数字 | ![]() |
| 红点 | ![]() |
| 多行文本 | ![]() |
| 多行富文本 | ![]() |
| Cell背景色渐变 | ![]() |
| 分割线 | ![]() |
| 说明 | Gif |
|---|---|
| 数据源过少 averageCellSpacingEnabled默认为YES |
![]() |
| 数据源过少 averageCellSpacingEnabled为NO |
![]() |
| SegmentedControl 参考 SegmentedControlViewController类 |
![]() |
| 导航栏使用 参考 NaviSegmentedControlViewController类 |
![]() |
| 嵌套使用 参考 NestViewController类 |
![]() |
| 个人主页(上下左右滚动、header悬浮) 参考 PagingViewController类更多样式请点击查看JXPagingView库 |
![]() |
| 垂直列表滚动 参考 VerticalListViewController类高仿腾讯视频 支持UITableView,参考 VerticalListTableViewController(背景色异常是录屏软件bug) |
![]() |
| 垂直缩放(仿网易圈圈、脉脉首页) 参考 ScrollZoomViewController类 |
![]() |
| 数据源刷新&列表数据加载 参考 LoadDataListContainerViewController类 |
![]() |
收录来自其他使用者的自定义示例,这些自定义类只在Demo项目里面,Pod库并没有这些文件。所以,如果你需要使用这些自定义效果,请通过文件导入的方式。
目的:
欢迎提PullRequest进行收录你的自定义效果。
| 说明 | Gif |
|---|---|
| Spring动画指示器 | ![]() |
| 富文本数量cell | ![]() |
| 左右对齐指示器 | ![]() |
| 秒杀时间线cell | ![]() |
| 京东商品排序cell | ![]() |
| title背景块cell | ![]() |
Clone代码,把Sources文件夹拖入项目,#import "JXCategoryView.h",就可以使用了;
target '<Your Target Name>' do
pod 'JXCategoryView'
end
先执行pod repo update,再执行pod install
1.初始化JXCategoryTitleView
self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, WindowsSize.width, 50)];
self.categoryView.delegate = self;
[self.view addSubview:self.categoryView];
2.配置JXCategoryTitleView的属性
self.categoryView.titles = @[@"螃蟹", @"麻辣小龙虾", @"苹果"...]
self.categoryView.titleColorGradientEnabled = YES;
3.添加指示器
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorLineViewColor = [UIColor redColor];
lineView.indicatorLineWidth = JXCategoryViewAutomaticDimension;
self.categoryView.indicators = @[lineView];
4.可选实现JXCategoryViewDelegate代理
//点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index;
//点击选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index;
//滚动选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index;
//正在滚动中的回调
- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio;
JXCategoryListContainerView封装类使用示例JXCategoryListContainerView是对列表视图高度封装的类,具有以下优点:
UIScrollView自定义,封装度高、代码集中、使用简单;1.初始化JXCategoryListContainerView并关联到categoryView
self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
[self.view addSubview:self.listContainerView];
//关联到categoryView
self.categoryView.listContainer = self.listContainerView;
2.实现JXCategoryListContainerViewDelegate代理方法
//返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
//根据下标index返回对应遵从`JXCategoryListContentViewDelegate`协议的列表实例
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
return [[ListViewController alloc] init];
}
3.列表实现JXCategoryListContentViewDelegate代理方法
不管列表是UIView还是UIViewController都可以,提高使用灵活性,更便于现有的业务接入。
// 返回列表视图
// 如果列表是VC,就返回VC.view
// 如果列表是View,就返回View自己
- (UIView *)listView {
return self.view;
}
具体点击LoadDataListContainerViewController查看源代码了解
因为代码量较多且分散,所有不推荐使用该方法。要正确使用需要注意的地方比较多,尤其对于刚接触iOS的同学来说不太友好。
不直接贴代码了,具体点击LoadDataListCustomViewController查看源代码了解。
❗️❗️❗️这里面包含了许多常见问题和答案,使用之前请务必浏览此文档,或者遇到问题先看此文档❗️❗️❗️
JXCategoryListContainerType的scrollView和collectionView对比FDFullscreenPopGesture等全屏手势处理reloadDataWithoutListContainer方法使用说明presentViewController方法JXCategoryListContainerView内部使用UIViewController当做列表容器使用说明JXCategoryIndicatorProtocol协议,点击参看JXCategoryIndicatorProtocolJXCategoryIndicatorProtocol协议的基类JXCategoryIndicatorComponentView,里面提供了许多基础属性。点击参看JXCategoryIndicatorComponentViewJXCategoryIndicatorView、JXCategoryIndicatorCell、JXCategoryIndicatorCellModel,就像JXCategoryTitleView、JXCategoryTitleCell、JXCategoryTitleCellModel那样去做;JXCategoryTitleImageView系列、JXCategoryTitleAttributeView系列那样去做;JXCategoryListContainerView,高度封装列表逻辑,支持懒加载列表,提升初始化性能;- (BOOL)selectCellAtIndex:(NSInteger)index selectedType:(JXCategoryCellSelectedType)selectedType,自定义有用到该接口的请及时更新。JXCategoryListCollectionContainerView.dataSource移动到m实现文件,添加- (instancetype)initWithDataSource:(id<JXCategoryListCollectionContainerViewDataSource>)dataSource初始化方法。- (void)categoryView:(JXCategoryBaseView *)categoryView didClickedItemContentScrollViewTransitionToIndex:(NSInteger)index;,请使用contentScrollViewClickTransitionAnimationEnabled属性。JXCategoryTitleVerticalZoomView进行了重构,内容左边距只需要使用contentEdgeLeft属性即可。JXCategoryListCollectionContainerView类新增和必须要调用- (void)scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio selectedIndex:(NSInteger)selectedIndex和- (void)didClickSelectedItemAtIndex:(NSInteger)index两个方法。如果刚开始使用JXCategoryView,当开发过程中需要支持某种特性时,请务必先搜索使用文档或者源代码。确认是否已经实现支持了想要的特性。请别不要文档和源代码都没有看,就直接提问,这对于大家都是一种时间浪费。如果没有支持想要的特性,欢迎提Issue讨论,或者自己实现提一个PullRequest。
该仓库保持随时更新,对于主流新的分类选择效果会第一时间支持。使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:317437084@qq.com QQ群: 112440473喜欢就star❤️一下吧
JXCategoryView is released under the MIT license.