Swift -- UIPickerView 与 UIDatePicker

今天小小的挖了一下 Swift 的 UIPickerView 跟 UIDatePicker 两个类相关的一些属性跟方法, 希望对广大初学者有所帮助.

  1. UIPickerView
    (1) UIPickerView 的常见属性
    // 数据源(确定 pickerView 的行列) weak public var dataSource: UIPickerViewDataSource? // 代理显示行列内容以及监听 pickerView 的选择 weak public var delegate: UIPickerViewDelegate? // 是否显示选中指示器 public var showsSelectionIndicator: Bool // default is NO // 列数 public var numberOfComponents: Int { get }
    (2) UIPickerView 的常见方法
    // 刷新所有列 public func reloadAllComponents() // 刷新指定列 public func reloadComponent(component: Int) // 主动选择指定行列 public func selectRow(row: Int, inComponent component: Int, animated: Bool) // 获取指定列选中的行号 public func selectedRowInComponent(component: Int) -> Int
    (3) UIPickerView 的数据源方法与代理方法(UIPickerViewDataSource && UIPickerViewDelegate)
    数据源:
    // 列数 public func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int // 行数 public func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int }
    代理方法:
    // 指定列宽度 optional public func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat // 指定列的行高 optional public func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat // 指定行列的显示文字 optional public func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? // 指定行列显示的 view optional public func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView // 选中指定行列 optional public func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
  2. UIDatePicker
    (1) 常见属性
    // 显示模式 public var datePickerMode: UIDatePickerMode // Time 显示时间 // Date 显示日期 // DateAndTime 显示日期和时间 default // CountDownTimer 显示时间 // 显示区域语言 public var locale: NSLocale? // 最大最小日期设置 public var minimumDate: NSDate? public var maximumDate: NSDate? // 通过 addTarget 监听
    (2) 使用
    // 可以使用往 alertView 上添加 view 的方式, 把 picker 添加到 alertView 上显示, 方法下 //[alert setValue:datePicker forKey:@"accessoryView"];
    如有不合理的地方, 欢迎指正!

你可能感兴趣的:(Swift -- UIPickerView 与 UIDatePicker)