Class
UIPickerView
A view that uses a spinning-wheel or slot-machine metaphor to show one or more sets of values.
--使用类似 旋转轮或老虎机的样式 来显示一组或多组值的视图。
Declaration
class UIPickerView : UIView
Overview
A picker view displays one or more wheels that the user manipulates to select items. Each wheel—known as a component—has a series of indexed rows representing the selectable items. Each row displays a string or view so that the user can identify the item on that row. Users select items by rotating the wheels to the desired values, which align with a selection indicator.
--选择器视图显示用户操作以选择项的一个或多个轮子。每个称为组件的“转轮”具有一系列索引行,表示可选择的项。每行显示一个字符串或视图,以便用户可以识别该行上的项。用户通过将轮子旋转到所需的值来选择项,这些值与选择中的项对齐。
Note
The UIDatePicker
class uses a custom subclass of UIPickerView
to display dates and times. To see an example, tap the add (“+”) button in the Alarm pane of the Clock app.
--UIDatePicker类使用UIPickerView的自定义子类来显示日期和时间。要查看示例,请单击“闹钟”应用程序的“闹钟”窗格中的“添加(+)”按钮。
You provide the data to be displayed in your picker view using a picker data source—an object that adopts the UIPickerViewDataSource
protocol. Use your picker view delegate—an object that adopts the UIPickerViewDelegate
protocol—to provide views for displaying your data and responding to user selections.
--你提供的数据将通过picker视图中使用的picker数据源来显示,这是一个遵循了UIPickerViewDataSource协议的对象。使用picker视图委托对象来提供显示你的数据和响应用户选择的视图,委托对象遵循了UIPickerViewDelegate协议。
Topics --专题
Providing the Picker Data --提供数据源
var dataSource: UIPickerViewDataSource?
The data source for the picker view.
protocol UIPickerViewDataSource
The UIPickerViewDataSource
protocol must be adopted by an object that mediates between a UIPickerView
object and your application’s data model for that picker view. The data source provides the picker view with the number of components, and the number of rows in each component, for displaying the picker view data. Both methods in this protocol are required.
Customizing the Picker Behavior --自定义选择器的行为
var delegate: UIPickerViewDelegate?
The delegate for the picker view.
The delegate of a UIPickerView
object must adopt this protocol and implement at least some of its methods to provide the picker view with the data it needs to construct itself.
Getting the Dimensions of the View Picker --获取选择器的维度
Gets the number of components for the picker view.
func numberOfRows(inComponent: Int) -> Int
Returns the number of rows for a component.
func rowSize(forComponent: Int) -> CGSize
Returns the size of a row for a component.
Reloading the View Picker --重新加载选择器
Reloads all components of the picker view.
Reloads a particular component of the picker view.
Selecting Rows in the View Picker --在选择器中选中某行
func selectRow(Int, inComponent: Int, animated: Bool)
Selects a row in a specified component of the picker view.
func selectedRow(inComponent: Int) -> Int
Returns the index of the selected row in a given component.
Returning the View for a Row and Component --获取指定行的view
func view(forRow: Int, forComponent: Int) -> UIView?
Returns the view used by the picker view for a given row and component.
Managing the Appearance of the Picker View --管理选择器额外观,丢弃
通过delegates来设置每一个row的外观吧
var showsSelectionIndicator: Bool
A Boolean value that determines whether the selection indicator is displayed.
Deprecated
Relationships --继承关系
Inherits From
Conforms To