UIPickerView and iosuipickerview in iOS development
Common attributes of UIPickerViewUIPickerView
// Data source (used to tell UIPickerView how many rows are there) @ property (nonatomic, assign) id <UIPickerViewDataSource> dataSource; // proxy (used to tell UIPickerView what is displayed in each row of each column and listen to the selection of UIPickerView) @ property (nonatomic, assign) id <UIPickerViewDelegate> delegate; // whether to display the selected indicator @ property (nonatomic) BOOL showsSelectionIndicator; // The total number of columns @ property (nonatomic, readonly) NSInteger numberOfComponents;
Common UIPickerView Methods
// Refresh all columns-(void) reloadAllComponents; // refresh the component column-(void) reloadComponent :( NSInteger) component; // actively select the row (void) selectRow :( NSInteger) row inComponent :( NSInteger) component animated :( BOOL) animated; // obtain the currently selected row number (NSInteger) selectedRowInComponent :( NSInteger) component in the component column;
Data Source Method (UIPickerViewDataSource)
// The total number of columns-(NSInteger) Partition :( UIPickerView *) pickerView; // The total number of rows in the component column-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component;
Proxy method (UIPickerViewDelegate)
// What is the width of the component column-(CGFloat) pickerView :( UIPickerView *) pickerView widthForComponent :( NSInteger) component; // What is the Row Height of the component column-(CGFloat) pickerView :( UIPickerView *) pickerView rowHeightForComponent :( NSInteger) component; // What text is displayed in the row of the component column-(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component; // view (content) of the row in the component column-(UIView *) pickerView :( UIPickerView *) pickerView viewForRow :( NSInteger) row forComponent :( NSInteger) component reusingView :( UIView *) view; // select the row (void) pickerView (UIPickerView *) of the component column of the pickerView) row inComponent :( NSInteger) component;
Note:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
The reuse view of this method is always blank after ios6. If you need to adapt to the system before ios6, you should take advantage of this view for performance considerations.
Before ios8, the height of UIPickerView is (162) and cannot be modified. After ios8.
Note:
If the height is not set or set to 0. The height is 216 by default.
If the configured height is greater than 0 and less than 180, the default height is 162.
If the set height is greater than or equal to 180 and less than 216, how is the height default value 180?
Width setting of pickerView:
If no width is specified during initialization, or the specified width is 0, the width is equal to the screen width by default.
Given a width not greater than 0, the width is equal to the given value.
UIDatePicker
UIDatePicker common attributes
// Display mode of datePicker @ property (nonatomic) UIDatePickerMode datePickerMode; // display region language @ property (nonatomic, retain) NSLocale * locale;
Monitor the selection of UIDatePicker
- Because UIDatePicker inherits from UIControl :... Listeners
Code to create a UIDatePicker
// 1. create date selector UIDatePicker * datePicker = [[UIDatePicker alloc] init]; // 2. set datePicker in the date display area. locale = [NSLocale localeWithLocaleIdentifier: @ "zh"]; // 3. set the date mode datePicker. datePickerMode = UIDatePickerModeTime; // 4.0 set the minimum time (the first 20 years from the current time) datePicker. minimumDate = [NSDate dateWithTimeIntervalSinceNow:-(365*24*3600*20)]; // 4.1 sets the maximum time (the last 20 years from the current time) datePicker. maximumDate = [NSDate dateWithTimeIntervalSince Now: 365*24*3600*20]; // 5. Set the time interval. (This interval must be able to divide 60) datePicker. minuteInterval = 6;