A powerful and easy to use segmented view (segmentedcontrol, pagingview, pagerview, pagecontrol, categoryview) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
Swift
2,879
263 commits
updated Jun 27, 2025

There is an English document here, click to view
A powerful and easy to use segmented view (segmentedcontrol, pagingview, pagerview, pagecontrol, categoryview) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
与其他的同类三方库对比的优点:
如果你在找Objective-C版本,请点击查看 JXCategoryView
| 说明 | Gif |
|---|---|
| Line固定宽度 | ![]() |
| Line与cell等宽 | ![]() |
| Line延长 | ![]() |
| Line延长+偏移 | ![]() |
| RainbowLine🌈彩虹 | ![]() |
| DotLine点线 | ![]() |
| DoubleLine双线 | ![]() |
| Triangle三角形底部 | ![]() |
| Triangle三角形顶部 | ![]() |
| Background椭圆形 | ![]() |
| Background椭圆形+阴影 | ![]() |
| Background遮罩有背景 | ![]() |
| Background遮罩无背景 | ![]() |
| Background渐变色 (渐变是固定的) | ![]() |
| Gradient渐变色 (渐变随着位置变动) | ![]() |
| Image底部 | ![]() |
| Image背景 | ![]() |
| 混合使用 | ![]() |
以下指示器支持上下位置切换:
JXSegmentedIndicatorLineView、JXSegmentedIndicatorRainbowLineView、JXSegmentedIndicatorDotLineView、JXSegmentedIndicatorDoubleLineView、JXSegmentedIndicatorTriangleView、JXSegmentedIndicatorImageView
| 说明 | Gif |
|---|---|
| 颜色渐变 | ![]() |
| 文字渐变 | ![]() |
| 大小缩放 | ![]() |
| 大小缩放+字体粗细 | ![]() |
| 大小缩放+点击动画 | ![]() |
| 大小缩放+cell宽度缩放 | ![]() |
| TitleImage_Top | ![]() |
| TitleImage_Left | ![]() |
| TitleImage_Bottom | ![]() |
| TitleImage_Right | ![]() |
| TitleImage_只有图片 | ![]() |
| TitleOrImage(高仿腾讯视频) | ![]() |
| 数字 | ![]() |
| 红点 | ![]() |
| 多行富文本 | ![]() |
| 多种cell混用 | ![]() |
| 说明 | Gif |
|---|---|
| 数据源过少 isItemSpacingAverageEnabled为true | ![]() |
| 数据源过少 isItemSpacingAverageEnabled为false | ![]() |
| SegmentedControl 参考 SegmentedControlViewController类 | ![]() |
| 导航栏使用 参考 NaviSegmentedControlViewController类 | ![]() |
| 嵌套使用 参考 NestViewController类 | ![]() |
| 个人主页(上下左右滚动、header悬浮) 参考 PagingViewController类更多样式请点击查看JXPagingView库 | ![]() |
| 数据加载&刷新 参考 LoadDataViewController类 | ![]() |
Clone代码,把Sources文件夹拖入项目,就可以使用了;
target '<Your Target Name>' do
pod 'JXSegmentedView'
end
先执行pod repo update,再执行pod install
在cartfile文件添加:
github "pujiaxin33/JXSegmentedView"
然后执行carthage update --platform iOS 即可
1.在Package.swift文件添加如下代码:
dependencies: [
.package(url: "https://github.com/pujiaxin33/JXSegmentedView.git", from: "1.2.1")
]
2.使用命令行构建:
$ swift build
JXSegmentedView使用示例1.初始化JXSegmentedView
segmentedView = JXSegmentedView()
segmentedView.delegate = self
view.addSubview(self.segmentedView)
2.初始化dataSource
dataSouce类型为JXSegmentedViewDataSource协议。使用单独的类实现JXSegmentedViewDataSource协议,实现代码隔离。选择不同的类赋值给dataSource,就可以控制JXSegmentedView显示效果,实现插件化。比如选择JXSegmentedTitleImageDataSource类作为dataSource就选择了文字图片的显示效果;选择JXSegmentedNumberDataSource类作为dataSource就选择了文字加数字的显示效果;
//segmentedDataSource一定要通过属性强持有,不然会被释放掉
segmentedDataSource = JXSegmentedTitleDataSource()
//配置数据源相关配置属性
segmentedDataSource.titles = ["猴哥", "青蛙王子", "旺财"]
segmentedDataSource.isTitleColorGradientEnabled = true
//关联dataSource
segmentedView.dataSource = self.segmentedDataSource
3.初始化指示器indicator
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 20
segmentedView.indicators = [indicator]
4.可选实现JXSegmentedViewDelegate代理
//点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {}
// 点击选中的情况才会调用该方法
func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {}
// 滚动选中的情况才会调用该方法
func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {}
// 正在滚动中的回调
func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {}
contentScrollView列表容器使用示例UIScrollView自定义使用示例因为代码比较分散,而且代码量也比较多,所有不推荐使用该方法。要正确使用需要注意的地方比较多,尤其对于刚接触iOS的同学来说不太友好。
不直接贴代码了,具体点击LoadDataCustomViewController查看源代码了解。
作为替代,官方使用&强烈推荐使用下面这种方式👇👇👇。
JXSegmentedListContainerView封装类使用示例JXSegmentedListContainerView是对列表视图高度封装的类,具有以下优点:
UIScrollView自定义,封装度高、代码集中、使用简单;1.初始化JXSegmentedListContainerView
listContainerView = JXSegmentedListContainerView(dataSource: self)
view.addSubview(self.listContainerView)
//关联listContainer
segmentedView.listContainer = listContainerView
2.实现JXSegmentedListContainerViewDataSource代理方法
//返回列表的数量
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return segmentedDataSource.titles.count
}
//返回遵从`JXSegmentedListContainerViewListDelegate`协议的实例
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
return ListBaseViewController()
}
3.列表实现JXSegmentedListContainerViewListDelegate代理方法
不管列表是UIView还是UIViewController都可以,提高使用灵活性,更便于现有的业务接入。
/// 如果列表是VC,就返回VC.view
/// 如果列表是View,就返回View自己
/// - Returns: 返回列表视图
func listView() -> UIView {
return view
}
func listWillAppear() {}
func listDidAppear() {}
func listDidDisappear() {}
func listDidDisappear() {}
具体点击LoadDataViewController查看源代码了解
因为JXSegmentedView本身支持许多特性:指示器、cell样式、列表容器等,如何有序管理好代码成了一个难题。借助于协议、继承、封装类极大的简化了使用难度,而且提高了灵活性,扩展相当容易。
JXSegmentedViewJXSegmentedViewDataSource协议的类JXSegmentedIndicatorProtocol协议的UIView类JXSegmentedListContainerView类,特殊情况可以使用UIScrollView自定义JXSegmentedIndicatorProtocol协议,点击参看JXSegmentedIndicatorProtocolJXSegmentedIndicatorProtocol协议的基类JXSegmentedIndicatorBaseView,里面提供了许多基础属性。点击参看JXSegmentedIndicatorBaseViewJXSegmentedViewDataSource协议,点击参看JXSegmentedViewDataSourceJXSegmentedViewDataSource协议的基类JXSegmentedBaseDataSource,里面提供了许多基础属性。点击参看JXSegmentedBaseDataSource如果刚开始使用JXSegmentedView,当开发过程中需要支持某种特性时,请务必先搜索使用文档或者源代码。确认是否已经实现支持了想要的特性。请别不要文档和源代码都没有看,就直接提问,这对于大家都是一种时间浪费。如果没有支持想要的特性,欢迎提Issue讨论,或者自己实现提一个PullRequest。
该仓库保持及时更新,对于主流新的分类选择效果会第一时间支持。使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:[email protected]
QQ群: 112440276
喜欢就star❤️一下吧
JXSegmentedView is released under the MIT license.
102 followers · starred Jun 2025
2,800 followers · starred Apr 2020
90 followers · starred Jun 2019
A powerful and easy to use segmented view (segmentedcontrol, pagingview, pagerview, pagecontrol, categoryview) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
Swift
2,879
263 commits
updated Jun 27, 2025

There is an English document here, click to view
A powerful and easy to use segmented view (segmentedcontrol, pagingview, pagerview, pagecontrol, categoryview) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
与其他的同类三方库对比的优点:
如果你在找Objective-C版本,请点击查看 JXCategoryView
| 说明 | Gif |
|---|---|
| Line固定宽度 | ![]() |
| Line与cell等宽 | ![]() |
| Line延长 | ![]() |
| Line延长+偏移 | ![]() |
| RainbowLine🌈彩虹 | ![]() |
| DotLine点线 | ![]() |
| DoubleLine双线 | ![]() |
| Triangle三角形底部 | ![]() |
| Triangle三角形顶部 | ![]() |
| Background椭圆形 | ![]() |
| Background椭圆形+阴影 | ![]() |
| Background遮罩有背景 | ![]() |
| Background遮罩无背景 | ![]() |
| Background渐变色 (渐变是固定的) | ![]() |
| Gradient渐变色 (渐变随着位置变动) | ![]() |
| Image底部 | ![]() |
| Image背景 | ![]() |
| 混合使用 | ![]() |
以下指示器支持上下位置切换:
JXSegmentedIndicatorLineView、JXSegmentedIndicatorRainbowLineView、JXSegmentedIndicatorDotLineView、JXSegmentedIndicatorDoubleLineView、JXSegmentedIndicatorTriangleView、JXSegmentedIndicatorImageView
| 说明 | Gif |
|---|---|
| 颜色渐变 | ![]() |
| 文字渐变 | ![]() |
| 大小缩放 | ![]() |
| 大小缩放+字体粗细 | ![]() |
| 大小缩放+点击动画 | ![]() |
| 大小缩放+cell宽度缩放 | ![]() |
| TitleImage_Top | ![]() |
| TitleImage_Left | ![]() |
| TitleImage_Bottom | ![]() |
| TitleImage_Right | ![]() |
| TitleImage_只有图片 | ![]() |
| TitleOrImage(高仿腾讯视频) | ![]() |
| 数字 | ![]() |
| 红点 | ![]() |
| 多行富文本 | ![]() |
| 多种cell混用 | ![]() |
| 说明 | Gif |
|---|---|
| 数据源过少 isItemSpacingAverageEnabled为true | ![]() |
| 数据源过少 isItemSpacingAverageEnabled为false | ![]() |
| SegmentedControl 参考 SegmentedControlViewController类 | ![]() |
| 导航栏使用 参考 NaviSegmentedControlViewController类 | ![]() |
| 嵌套使用 参考 NestViewController类 | ![]() |
| 个人主页(上下左右滚动、header悬浮) 参考 PagingViewController类更多样式请点击查看JXPagingView库 | ![]() |
| 数据加载&刷新 参考 LoadDataViewController类 | ![]() |
Clone代码,把Sources文件夹拖入项目,就可以使用了;
target '<Your Target Name>' do
pod 'JXSegmentedView'
end
先执行pod repo update,再执行pod install
在cartfile文件添加:
github "pujiaxin33/JXSegmentedView"
然后执行carthage update --platform iOS 即可
1.在Package.swift文件添加如下代码:
dependencies: [
.package(url: "https://github.com/pujiaxin33/JXSegmentedView.git", from: "1.2.1")
]
2.使用命令行构建:
$ swift build
JXSegmentedView使用示例1.初始化JXSegmentedView
segmentedView = JXSegmentedView()
segmentedView.delegate = self
view.addSubview(self.segmentedView)
2.初始化dataSource
dataSouce类型为JXSegmentedViewDataSource协议。使用单独的类实现JXSegmentedViewDataSource协议,实现代码隔离。选择不同的类赋值给dataSource,就可以控制JXSegmentedView显示效果,实现插件化。比如选择JXSegmentedTitleImageDataSource类作为dataSource就选择了文字图片的显示效果;选择JXSegmentedNumberDataSource类作为dataSource就选择了文字加数字的显示效果;
//segmentedDataSource一定要通过属性强持有,不然会被释放掉
segmentedDataSource = JXSegmentedTitleDataSource()
//配置数据源相关配置属性
segmentedDataSource.titles = ["猴哥", "青蛙王子", "旺财"]
segmentedDataSource.isTitleColorGradientEnabled = true
//关联dataSource
segmentedView.dataSource = self.segmentedDataSource
3.初始化指示器indicator
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 20
segmentedView.indicators = [indicator]
4.可选实现JXSegmentedViewDelegate代理
//点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {}
// 点击选中的情况才会调用该方法
func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {}
// 滚动选中的情况才会调用该方法
func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {}
// 正在滚动中的回调
func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {}
contentScrollView列表容器使用示例UIScrollView自定义使用示例因为代码比较分散,而且代码量也比较多,所有不推荐使用该方法。要正确使用需要注意的地方比较多,尤其对于刚接触iOS的同学来说不太友好。
不直接贴代码了,具体点击LoadDataCustomViewController查看源代码了解。
作为替代,官方使用&强烈推荐使用下面这种方式👇👇👇。
JXSegmentedListContainerView封装类使用示例JXSegmentedListContainerView是对列表视图高度封装的类,具有以下优点:
UIScrollView自定义,封装度高、代码集中、使用简单;1.初始化JXSegmentedListContainerView
listContainerView = JXSegmentedListContainerView(dataSource: self)
view.addSubview(self.listContainerView)
//关联listContainer
segmentedView.listContainer = listContainerView
2.实现JXSegmentedListContainerViewDataSource代理方法
//返回列表的数量
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return segmentedDataSource.titles.count
}
//返回遵从`JXSegmentedListContainerViewListDelegate`协议的实例
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
return ListBaseViewController()
}
3.列表实现JXSegmentedListContainerViewListDelegate代理方法
不管列表是UIView还是UIViewController都可以,提高使用灵活性,更便于现有的业务接入。
/// 如果列表是VC,就返回VC.view
/// 如果列表是View,就返回View自己
/// - Returns: 返回列表视图
func listView() -> UIView {
return view
}
func listWillAppear() {}
func listDidAppear() {}
func listDidDisappear() {}
func listDidDisappear() {}
具体点击LoadDataViewController查看源代码了解
因为JXSegmentedView本身支持许多特性:指示器、cell样式、列表容器等,如何有序管理好代码成了一个难题。借助于协议、继承、封装类极大的简化了使用难度,而且提高了灵活性,扩展相当容易。
JXSegmentedViewJXSegmentedViewDataSource协议的类JXSegmentedIndicatorProtocol协议的UIView类JXSegmentedListContainerView类,特殊情况可以使用UIScrollView自定义JXSegmentedIndicatorProtocol协议,点击参看JXSegmentedIndicatorProtocolJXSegmentedIndicatorProtocol协议的基类JXSegmentedIndicatorBaseView,里面提供了许多基础属性。点击参看JXSegmentedIndicatorBaseViewJXSegmentedViewDataSource协议,点击参看JXSegmentedViewDataSourceJXSegmentedViewDataSource协议的基类JXSegmentedBaseDataSource,里面提供了许多基础属性。点击参看JXSegmentedBaseDataSource如果刚开始使用JXSegmentedView,当开发过程中需要支持某种特性时,请务必先搜索使用文档或者源代码。确认是否已经实现支持了想要的特性。请别不要文档和源代码都没有看,就直接提问,这对于大家都是一种时间浪费。如果没有支持想要的特性,欢迎提Issue讨论,或者自己实现提一个PullRequest。
该仓库保持及时更新,对于主流新的分类选择效果会第一时间支持。使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:[email protected]
QQ群: 112440276
喜欢就star❤️一下吧
JXSegmentedView is released under the MIT license.
102 followers · starred Jun 2025
2,800 followers · starred Apr 2020
90 followers · starred Jun 2019