{"id":15038759,"url":"https://github.com/elenionl/elpickerview-swift","last_synced_at":"2025-04-10T00:02:27.887Z","repository":{"id":56909454,"uuid":"89040622","full_name":"Elenionl/ELPickerView-Swift","owner":"Elenionl","description":"A Picker View with animation build in Swift 3","archived":false,"fork":false,"pushed_at":"2018-01-22T05:14:39.000Z","size":2505,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T00:01:26.726Z","etag":null,"topics":["picker","picker-component","pickerview","swift","swift-3"],"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/Elenionl.png","metadata":{"files":{"readme":"README IN CHINESE.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-22T03:06:18.000Z","updated_at":"2019-10-25T01:32:58.000Z","dependencies_parsed_at":"2022-08-20T19:40:08.236Z","dependency_job_id":null,"html_url":"https://github.com/Elenionl/ELPickerView-Swift","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elenionl%2FELPickerView-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elenionl%2FELPickerView-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elenionl%2FELPickerView-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elenionl%2FELPickerView-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elenionl","download_url":"https://codeload.github.com/Elenionl/ELPickerView-Swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131322,"owners_count":21052819,"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":["picker","picker-component","pickerview","swift","swift-3"],"created_at":"2024-09-24T20:40:04.874Z","updated_at":"2025-04-10T00:02:27.847Z","avatar_url":"https://github.com/Elenionl.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"ELPickerView: 简单易用的 Picker View, 使用 Swift 4 开发\n======================================\n\n[![Build Status](https://travis-ci.org/Elenionl/ELPickerView-Swift.svg?branch=master)](https://travis-ci.org/Elenionl/ELPickerView-Swift)\n[![Apps Using](https://img.shields.io/cocoapods/at/ELPickerView.svg?label=Apps%20Using%20ELPickerView\u0026colorB=28B9FE)](http://cocoapods.org/pods/ELPickerView)\n[![Downloads](https://img.shields.io/cocoapods/dt/ELPickerView.svg?label=Total%20Downloads\u0026colorB=28B9FE)](http://cocoapods.org/pods/ELPickerView)\n[![CocoaPods](https://img.shields.io/cocoapods/v/ELPickerView.svg?style=flat)](https://cocoapods.org/pods/ELPickerView)\n[![CocoaPods](https://img.shields.io/cocoapods/l/ELPickerView.svg?style=flat)](https://cocoapods.org/pods/ELPickerView)\n[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-blue.svg)](https://img.shields.io/badge/Swift-3.0-blue.svg)\n[![iOS 8.0](https://img.shields.io/badge/iOS-8.0-blue.svg)](https://img.shields.io/badge/iOS-8.0-blue.svg)\n**:warning: ELPickerView 适用于 Swift 3.**\n\n## Screenshots\n 简单易用的 Picker View, 使用 Swift 4 开发\n\n\n![screenshots_4](https://raw.githubusercontent.com/Elenionl/ELPickerView-Swift/master/screenshots/screenshots_4.gif)\n-----------\n\n## 安装方法\n\n### 使用 [CocoaPods](https://cocoapods.org/pods/ELPickerView)\n-----------\n* 在 ``podfile`` 中添加下面一行代码 :\n``pod 'ELPickerView'``\n* 使用 Terminal 运行 `pod install`\n* Swift 3* 使用 3.0.0 pod 版本\n* Swift 4* 使用 4.* pod 版本\n* 完成!\n-----------\n### 直接添加\n* 用浏览器打开 [Elenionl/ELPickerView-Swift](https://github.com/Elenionl/ELPickerView-Swift)\n* 下载或克隆项目: ``https://github.com/Elenionl/ELPickerView-Swift.git``\n* 复制项目中的 ``ELCustomPickerView.swift`` 文件到您的项目中\n* 完成!\n\n------------\n## 如何使用\n\n### ELPickerView 十分简便,使用仅需要两步:\n* 构造\n```Swift\nlazy var customPickerView: ELCustomPickerView\u003cString\u003e = {\n    return ELCustomPickerView\u003cString\u003e(pickerType: .singleComponent, items: [\n        \"Row 0\"\n        , \"Row 1\"\n        , \"Row 2\"\n        , \"Row 3\"\n        , \"Row 4\"\n        , \"Row 5\"\n        ])\n}\n```\n* 展示\n```Swift\noverride func viewDidLoad() {\n        super.viewDidLoad()\n        customPickerView.show(viewController: self, animated: true)\n}\n```\n------------\n### 如果想让 Picker View 的北京覆盖导航栏和工具栏\n\n* 只需要让 window 来展示 Picker View 代码如下:\n\n```Swift\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        customPickerView.show(viewController: nil, animated: true)\n    }\n```\n-------------\n### ELPickerView 中没有代理, 使用闭包来处理回调, 代码聚合性更好\n\n* 针对各种事件都有回调\n利用 Set 方法完成\n```Swift\n        view.setDidScrollHandler({ [weak self] (view, chosenIndex, chosenItem) -\u003e (shouldHide: Bool, animated: Bool) in\n            let hide = false\n            let animated = false\n            self?.logLabel.text = \"Did Scroll. \\n\u003cIndex: \\(chosenIndex)\u003e \\n\u003cchosenItem: \\(chosenItem)\u003e \\n\u003cHide: \\(hide)\u003e \\n\u003cAnimated: \\(animated)\u003e\"\n            print(self?.logLabel.text ?? \"\")\n            return (hide, animated)\n        })\n```\n直接设置\n```Swift\n        customPickerView.leftButtoTapHandler = { [weak self] (view: ELCustomPickerView\u003cString\u003e?, chosenIndex: Int, chosenItem: (key: String, content: String)) in\n            let hide = true\n            let animated = true\n            self?.logLabel.text = \"Did Tap Left Button. \u003cIndex: \\(chosenIndex)\u003e \u003cchosenItem: \\(chosenItem)\u003e \u003cHide: \\(hide)\u003e \u003cAnimated: \\(animated)\u003e\"\n            print(self?.logLabel.text ?? \"\")\n            return (hide, animated)\n        }\n```\n* 这个闭包是这样定义的\n```Swift\n    /// 当点击左侧按钮的时候出发\n    //  view: 触发时间的 Picker View\n    //  chosenIndex: Picker View 当前选中栏的 index\n    //  chosenItem: 当前选中栏的 index 所对应的 item 数据\n    //  shouldHide: 通知 Picker View 是否要隐藏, 默认是 true\n    //  animated: 通知 Picker View 隐藏时是否有动画, 默认是 true\n    public var leftButtoTapHandler: ((_ view: ELCustomPickerView?, _ chosenIndex: Int, _ chosenItem: T) -\u003e (shouldHide: Bool, animated: Bool))?\n```\n-------------------------\n### Picker View 中的栏目对用的不仅仅是 String, 也可是 **对象** **结构体** **枚举** 以及 **元组**\n\n* 使用方法: 构造时通过泛型指定 item 的类型, 并将带有 item 的数组作为参数传入构造函数\n```Swift\ntypealias CustomView = ELCustomPickerView\u003c(key: String, content: String)\u003e\n...\nlet view = CustomView(pickerType: .singleComponent, items: [\n          (\"00\", \"Row 0\")\n          , (\"02\", \"Row 1\")\n          , (\"04\", \"Row 2\")\n          , (\"06\", \"Row 3\")\n          , (\"09\", \"Row 4\")\n          , (\"11\", \"Row 5\")\n          ])\n```\n\n* 给 itemConfigHandler 属性赋值, 该属性是一个将 item 转化成 String 类型对象的闭包, 当为Picker View 提供数据的时候, ELPickerView 将会调用该闭包将 item 转化成要展现的条目\n```Swift\nview.itemConfigHandler = { (key: String, content: String) in\n    return content\n}\n```\n\n* 完成!\n-------------------------\n### Picker View 的配置也十分简单\n\n```Swift\n        view.blackBackground = true\n        view.isTitleBarHidden = false\n        view.isTapBackgroundEnabled = true\n        view.leftButton.setTitle(\"LEFT\", for: .normal)\n        view.rightButton.setTitle(\"RIGHT\", for: .normal)\n        view.title.text = \"TITLE\"\n        view.foregroundView.picker.backgroundColor = UIColor.white\n        view.foregroundView.bottomDivider.isHidden = true\n```\n----------------\n## 下面是可进行配置的相关属性\n\n```Swift\n// MARK: - Settings\n\n/// Type of Picker View\npublic let pickerType: ELCustomPickerViewType\n\n/// Items used to config Picker View rows  Default value is []\npublic var items: [T]\n\n/// Background of the screen  Default value is true\npublic var blackBackground: Bool\n\n/// Set Title Bar hidden or not  Default value is false\npublic var isTitleBarHidden = false\n\n/// Set Taping Background to hide Picker View enabled or not  Default value is true\npublic var isTapBackgroundEnabled = true\n\n/// Left Button of the Title Bar, shortcut to foregroundView.leftButton\npublic lazy var leftButton: UIButton\n\n/// Right Button of the Title Bar, shortcut to foregroundView.rightButton\npublic lazy var rightButton: UIButton\n\n/// Title of the Title Bar, shortcut to foregroundView.title\npublic lazy var title: UILabel\n\n\n// MARK: - Handler\n\n/// Function used to transform Item into String. If the Item is String kind, itemConfigHandler is not necessory to be set.\npublic var itemConfigHandler: ((T) -\u003e String)?\n/// Triggered when Left Button is tapped.\n//  view: the CustomPickerView\n//  chosenIndex: the current chosen index of row in Picker View\n//  chosenItem: the Item connected with the chosen row\n//  shouldHide: tell the Picker View whether it should be hide  Default value is true\n//  animated: tell the Picker View whether the hide action should have animation  Default value is true\npublic var leftButtoTapHandler: ((_ view: ELCustomPickerView?, _ chosenIndex: Int, _ chosenItem: T) -\u003e (shouldHide: Bool, animated: Bool))?\n\n/// Triggered when Right Button is tapped.\n//  view: the CustomPickerView\n//  chosenIndex: the current chosen index of row in Picker View\n//  chosenItem: the Item connected with the chosen row\n//  shouldHide: tell the Picker View whether it should be hide  Default value is true\n//  animated: tell the Picker View whether the hide action should have animation  Default value is true\npublic var rightButtoTapHandler: ((_ view: ELCustomPickerView?, _ chosenIndex: Int, _ chosenItem: T) -\u003e (shouldHide: Bool, animated: Bool))?\n\n/// Triggered when user picked one row in Picker View.\n//  view: the CustomPickerView\n//  chosenIndex: the current chosen index of row in Picker View\n//  chosenItem: the Item connected with the chosen row\n//  shouldHide: tell the Picker View whether it should be hide  Default value is false\n//  animated: tell the Picker View whether the hide action should have animation   Default value is false\npublic var didScrollHandler: ((_ view: ELCustomPickerView?, _ chosenIndex: Int, _ chosenItem: T) -\u003e (shouldHide: Bool, animated: Bool))?\n\n/// Triggered when Picker View will show\npublic var willShowHandler: ((_ view: ELCustomPickerView?) -\u003e Void)?\n\n/// Triggered when Picker View did show\npublic var didShowHandler: ((_ view: ELCustomPickerView?) -\u003e Void)?\n\n/// Triggered when Picker View will hide\npublic var willHideHandler: ((_ view: ELCustomPickerView?) -\u003e Void)?\n\n/// Triggered when Picker View did hide\npublic var didHideHandler: ((_ view: ELCustomPickerView?) -\u003e Void)?\n\n// MARK: - Views\n\n/// The bottom view containing Title Bar and Picker\npublic lazy var foregroundView: ELPickerForegroundView\n```\n----------------\n## 需求\n\n* Xcode 8.0\n* Swift 3.0\n* 使用 ARC\n* iOS 8.0\n-------------------\n## 作者\n\nHanping Xu ([Elenionl](https://github.com/Elenionl)), stellanxu@gmail.com\n\n\n-------------------\n## 协议\n\nELPickerView is available under the MIT license, see the LICENSE file for more information.   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felenionl%2Felpickerview-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felenionl%2Felpickerview-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felenionl%2Felpickerview-swift/lists"}