垂直 | 水平 |
---|---|
![]() |
![]() |
滑动动画 | 展开动画 | 翻转动画 |
---|---|---|
![]() |
![]() |
![]() |
import ZTDropDownTextField
在任何需要的地方包含 ZTDropDownTextField。ZTDropDownTextField.xcworkspace
文件查看提供的示例应用程序了解如何使用 ZTDropDownTextField。
将以下导入添加到需要下拉文本字段的 Swift 文件顶部。
import ZTDropDownTextField
你可以使用 IBOutlet 声明 ZTDropDownTextField 并将其连接到你的 storyboard 或 nib 文件。
@IBOutlet weak var dropDownTextField: ZTDropDownTextField!
如果你的视图控制器遵循了 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
可以通过修改这两个变量的值来自定义 rowHeight
和 dropDownTableViewHeight
:
public var rowHeight:CGFloat = 50
public var dropDownTableViewHeight: CGFloat = 150
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.