ZTDropDownTextField 0.1.5

ZTDropDownTextField 0.1.5

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2015年8月
SPM支持 SPM

Ziyang Tan 维护。



  • Ziyang Tan

目录


功能

  • [x] 在 UITextField 下方提供下拉建议
  • [x] UISearchController 的替代品
  • [x] 用户点击下拉列表之外的任何地方时,下拉列表将自动隐藏
  • [x] 使用 AutoLayout 实现,支持横竖屏
  • [x] 提供下拉列表事件的代理方法
  • [x] 下拉列表 UI 可自定义
  • [x] Swift Dynamic Framework,易于集成

演示

垂直 水平
Portrait Slide Animation
滑动动画 展开动画 翻转动画
Slide Animation Slide Animation Flip Animation

安装

源文件

  1. 下载最新的代码版本 (master.zip) 或将仓库作为 git 子模块添加到你的 git 追踪项目。
  2. 从归档中拖放到你的项目导航器中的 ZTDropDownTextField 目录。如果将代码存档提取到项目外部,请确认在询问时选择 复制项目
  3. 通过 import ZTDropDownTextField 在任何需要的地方包含 ZTDropDownTextField。

示例

  1. 下载最新的代码版本 (master.zip)
  2. 双击打开 ZTDropDownTextField.xcworkspace 文件

使用

查看提供的示例应用程序了解如何使用 ZTDropDownTextField。

基本

将以下导入添加到需要下拉文本字段的 Swift 文件顶部。

   import ZTDropDownTextField

IBOutlet

你可以使用 IBOutlet 声明 ZTDropDownTextField 并将其连接到你的 storyboard 或 nib 文件。

  @IBOutlet weak var dropDownTextField: ZTDropDownTextField!

DataSourceDelegate

如果你的视图控制器遵循了 ZTDropDownTextFieldDataSourceDelegate,你必须实现以下 3 个代理方法。

你可以通过以下操作使视图控制器成为 ZTDropDownTextFieldDataSourceDelegate

  dropDownTextField.dataSourceDelegate = self

ZTDropDownTextFieldDataSourceDelegate 方法的实现示例

extension ViewController: ZTDropDownTextFieldDataSourceDelegate {
    func dropDownTextField(dropDownTextField: ZTDropDownTextField, numberOfRowsInSection section: Int) -> Int {
        return myList.count
    }

    func dropDownTextField(dropDownTextField: ZTDropDownTextField, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = dropDownTextField.dropDownTableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
        if cell == nil {
            cell = UITableViewCell(style: .Default, reuseIdentifier: "Cell")
        }

        cell!.textLabel!.text = myList[indexPath.row]

        return cell!
    }

    func dropDownTextField(dropdownTextField: ZTDropDownTextField, didSelectRowAtIndexPath indexPath: NSIndexPath) {
       println("drop down list row did select")
    }
}

自定义

下拉列表可以有 3 种不同的动画效果,包括 基本滑动展开翻转。请查看 示例 中的动画。

public enum ZTDropDownAnimationStyle {
    case Basic
    case Slide
    case Expand
    case Flip
}
  dropDownTextField.animationStyle = .Slide

可以通过修改这两个变量的值来自定义 rowHeightdropDownTableViewHeight

  public var rowHeight:CGFloat = 50
  public var dropDownTableViewHeight: CGFloat = 150

要求

  • Xcode 6
  • iOS 7
  • ARC
  • 框架
    • UIKit

待办事项

  • [ ] Swift 2.0
  • [ ] 更多自定义选项

致谢

许可证

The MIT License (MIT)

Copyright (c) 2015 Ziyang Tan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.