测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年1月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✗ |
由 Emre Duman 维护。
为 iOS 定制的下拉列表。使用 swift3 编写。
将 TDDropdownList.swift
文件拖入您的项目结构中
import UIKit
import TDDropdownList
class ViewController: UIViewController , TDDropdownListDelegate {
let list = TDDropdownList(frame: CGRect(x:60 , y : 100 , width: 200 , height: 50))
override func viewDidLoad() {
list.initialize(data: ["Github","Theduman","Dropdown","List"])
list.delegate = self
self.view.addSubview(list)
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func listTapped(sender: UIButton) {
let alert = UIAlertController(title: "TDDropdownList" ,message: "Selected item: \(sender.currentTitle!)", preferredStyle:.alert)
alert.addAction(UIAlertAction(title:"OK", style: .default, handler:nil))
self.present(alert, animated: true, completion: nil)
}
}
要获取下拉列表选中项,您需要符合 TDDropdownListDelegate。
将字符串数组传递给您想要显示的 initialize()
函数。
initialize(data: [String],selectedItemColor: UIColor = UIColor(red:0.74, green:0.03, blue:0.11, alpha:1.00),itemColor:UIColor = UIColor(red:0.03, green:0.30, blue:0.53, alpha:1.00),textColor: UIColor = .white,selectedItemPlaceholder:String = "\u{02304}" , animationTimer: Double = 0.5)
您可以在 initialize()
函数中自定义库的 UI。
您可以;
selectedItemColor: UIColor
参数更改选中项的背景颜色itemColor:UIColor
参数更改扩展项目的背景颜色textColor: UIColor
参数更改文本颜色selectedItemPlaceholder:String
参数更改第一次运行时选中项的占位符。您也可以提供 Unicode 字符。animationTimer: Double
参数更改展开动画的时间