{"id":13990688,"url":"https://github.com/choiceyou/FWSegmentedControl","last_synced_at":"2025-07-22T13:30:53.196Z","repository":{"id":56910884,"uuid":"125063484","full_name":"choiceyou/FWSegmentedControl","owner":"choiceyou","description":"分段控件：支持纯文字、纯图片、文字图片混排等方式的Segment，文字、图片排布顺序可选，同时有多重可选下标，更多配置请参考”可设置参数“。提供OC使用Demo。","archived":false,"fork":false,"pushed_at":"2020-10-29T03:17:49.000Z","size":12548,"stargazers_count":95,"open_issues_count":0,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-31T16:20:05.123Z","etag":null,"topics":["objective-c","pod","segment","swift","viewpager"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/choiceyou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-13T14:22:27.000Z","updated_at":"2024-10-25T07:56:47.000Z","dependencies_parsed_at":"2022-08-21T04:20:45.347Z","dependency_job_id":null,"html_url":"https://github.com/choiceyou/FWSegmentedControl","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choiceyou%2FFWSegmentedControl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choiceyou%2FFWSegmentedControl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choiceyou%2FFWSegmentedControl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choiceyou%2FFWSegmentedControl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/choiceyou","download_url":"https://codeload.github.com/choiceyou/FWSegmentedControl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227098930,"owners_count":17730672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["objective-c","pod","segment","swift","viewpager"],"created_at":"2024-08-09T13:03:06.800Z","updated_at":"2024-11-29T10:31:20.357Z","avatar_url":"https://github.com/choiceyou.png","language":"Swift","readme":"# ![](https://github.com/choiceyou/FWSegmentedControl/blob/master/%E6%95%88%E6%9E%9C/FWSegmentedControl.png)\n\n[![Platform](http://img.shields.io/badge/platform-iOS-blue.svg?style=flat)](http://cocoapods.org/?q=FWSegmentedControl)\u0026nbsp;\n![Language](https://img.shields.io/badge/language-swift-orange.svg?style=flat)\u0026nbsp;\n[![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/choiceyou/FWSegmentedControl/blob/master/FWSegmentedControl/LICENSE)\n\n\n\n## 支持pod导入：\n\n```cocoaPods\nuse_frameworks!\npod 'FWSegmentedControl'\n注意：\n1、如出现 [!] Unable to find a specification for 'FWSegmentedControl' 错误 或 看不到最新的版本，\n  可执行 pod repo update 命令更新一下本地pod仓库。\n2、use_frameworks! 的使用：\n（1）纯OC项目中，通过cocoapods导入OC库时，一般都不使用use_frameworks!\n（2）纯swift项目中，通过cocoapods导入swift库时，必须使用use_frameworks!\n（3）只要是通过cocoapods导入swift库时，都必须使用use_frameworks!\n（4）使用动态链接库dynamic frameworks时，必须使用use_frameworks!\n```\n\n\n## 可设置参数：\n```参数\n/// 标题\n@objc public var sectionTitleArray: [String]?\n/// 图片\n@objc public var sectionImageArray: [UIImage]?\n/// 选中图片\n@objc public var sectionSelectedImageArray: [UIImage]?\n\n/// segment类型\n@objc public var scType = SCType.text\n/// segment宽度\n@objc public var scWidthStyle = SCWidthStyle.fixed\n/// 图片相对于文字的位置\n@objc public var scImagePosition: SCImagePosition = .leftOfText\n/// 选中标识符类型\n@objc public var scSelectionIndicatorStyle = SCSelectionIndicatorStyle.contentWidthStripe\n/// 选中标识符位置\n@objc public var scSelectionIndicatorLocation = SCSelectionIndicatorLocation.down\n/// 边框类型\npublic var scBorderType: SCBorderType = .none\n\n/// 选中标识符高度，注意：self.scSelectionIndicatorStyle == .box || self.scSelectionIndicatorStyle == .none 时无效\n@objc public var selectionIndicatorHeight: CGFloat = 3.0\n/// 选中标识符，当 SCSelectionIndicatorLocation == up 时，底部edge无效；反之，顶部edge无效；\n@objc public var selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)\n/// 选中标识符颜色\n@objc public var selectionIndicatorColor = UIColor.red\n@objc public var selectionIndicatorBoxColor = UIColor.gray\n\n/// 滑动或者选中回调\n@objc public var indexChangeBlock: SCIndexChangeBlock?\n/// 标题NSAttributedString回调\n@objc public var titleFormatterBlock: SCTitleFormatterBlock?\n/// segment的Inset属性\n@objc public var segmentEdgeInset = UIEdgeInsetsMake(0, 5, 0, 5)\n@objc public var enlargeEdgeInset = UIEdgeInsetsMake(0, 0, 0, 0)\n\n/// 未选中的标题属性\n@objc public var titleTextAttributes: [NSAttributedStringKey: Any]?\n/// 选中的标题属性\n@objc public var selectedTitleTextAttributes: [NSAttributedStringKey: Any]?\n\n/// 是否可以拖动\n@objc public var userDraggable = true\n/// 是否可以点击\n@objc public var touchEnabled = true\n\n/// segment的边框颜色\n@objc public var segmentBorderColor = UIColor.black\n/// segment的边框大小\n@objc public var segmentBorderWidth: CGFloat = 1.0\n\n/// 选中或者滑动时是否需要动画\n@objc public var shouldAnimateUserSelection = true\n\n/// 选中标识符为箭头的宽度\n@objc public var arrowWidth: CGFloat = 6.0\n\n/// 选中表示符为box时的opacity值\n@objc public var selectionIndicatorBoxOpacity: CGFloat = 0.2\n\n/// segment之间的间隔竖线的宽度\n@objc public var verticalDividerWidth: CGFloat = 1.0\n/// 是否需要segment之间的间隔竖线\n@objc public var verticalDividerEnabled = false\n/// segment之间的间隔竖线的颜色\n@objc public var verticalDividerColor = UIColor.black\n\n/// 选中标识符滑动的时间\n@objc public var indicatorAnimatedTimes: CFTimeInterval = 0.15\n\n/// self.scType == .textImages 时，文字、图片的间隔\n@objc public var textImageSpacing: CGFloat = 4.0\n\n/// 选中项的下标\n@objc public var selectedSegmentIndex: Int = 0\n```\n\n\n\n## 简单使用：（注：可下载demo具体查看，分别有OC、Swift的demo）\n\n```swift\n/// 类初始化方法\n///\n/// - Parameters:\n///   - scType: segment类型\n///   - sectionTitleArray: 标题，可传nil，后续再设置\n///   - sectionImageArray: 图片，可传nil，后续再设置\n///   - sectionSelectedImageArray: 选中图片，可传nil，后续再设置\n///   - frame: frame\n@objc open class func segmentedWith(scType: SCType,\n                              scWidthStyle: SCWidthStyle,\n                         sectionTitleArray: [String]?,\n                         sectionImageArray: [UIImage]?,\n                 sectionSelectedImageArray: [UIImage]?,\n                                     frame: CGRect) -\u003e FWSegmentedControl\n```\n\n### OC：\n```oc\n[FWSegmentedControl segmentedWithScType: SCTypeText\n                           scWidthStyle: SCWidthStyleDynamicFixedSuper\n                      sectionTitleArray: @[@\"关注\", @\"游戏\", @\"附近\"]\n                      sectionImageArray: nil \n              sectionSelectedImageArray: nil\n                                  frame: CGRectMake(0, 40, self.view.frame.size.width, 50)];\n```\n\n\n### Swift: \u003cbr\u003e\n```swift\nFWSegmentedControl.segmentedWith(scType: SCType.text,\n                           scWidthStyle: SCWidthStyle.fixed,\n                      sectionTitleArray: [\"关注\", \"游戏\", \"附近\"],\n                      sectionImageArray: nil,\n              sectionSelectedImageArray: nil,\n                                  frame: CGRect(x: 0, y: 40, width: Int(UIScreen.main.bounds.width), height: 50)) \n\n```\n\n\n\n## 效果：\n\n![](https://github.com/choiceyou/FWSegmentedControl/blob/master/%E6%95%88%E6%9E%9C/%E7%A4%BA%E4%BE%8B1.gif)\n![](https://github.com/choiceyou/FWSegmentedControl/blob/master/%E6%95%88%E6%9E%9C/%E7%A4%BA%E4%BE%8B2.gif)\n\n\n\n## 注意点：\n\n一、本UI库是用Swift4.0编写的，所以安装或者拖入文件后需要把对应的Swift设置为4.0版本： \u003cbr\u003e\n（1）pod安装方式：![](https://github.com/choiceyou/FWSegmentedControl/blob/master/%E6%95%88%E6%9E%9C/%E8%AE%BE%E7%BD%AE1.jpg)\n（2）文件拖入方式：Targets --\u003e Build Setting 做相同的设置\n\n二、如果是文件拖入方式，需要设置OC、Swift混编等，相关问题网上有很多解答，我这边就不再重复了\n\n\n\n## 更新记录：\n\n• v2.1.7：\n- [x] 添加：sectionSelectedImageDict，使得在一个FWSegmentedControl中支持图片+文字、图片、文字的混排形式；\n- [x] 选中标识符可设置圆角，默认圆角值为：1.5f；\n- [x] 新增已经选中了某个index后再次点击的回调：SCIndexSecondClickedBlock；\n- [x] 修复segmentEdgeInset位置右移的问题；\n- [x] 更多细节调整；\n\n\n\n## 结尾语：\n\n- 使用过程中发现bug请issues或加入FW问题反馈群：670698309（此群只接受FW相关组件问题）；\n- 有新的需求欢迎提出；\n\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoiceyou%2FFWSegmentedControl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchoiceyou%2FFWSegmentedControl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoiceyou%2FFWSegmentedControl/lists"}