Common Properties of Uipickerviewuipickerview
//Data source (used to tell Uipickerview how many rows are in the row)@property(nonatomic,Assign)ID<UIPickerViewDataSource> DataSource;//Agent (used to tell Uipickerview what to display on every 1 rows of every 1 columns, and to monitor the selection of Uipickerview)@property(nonatomic,Assign)ID<UIPickerViewDelegate> delegate;//Whether to display the selected indicator@property(nonatomic)BOOLShowsselectionindicator;//How many columns are there altogether@property(nonatomic,ReadOnly)Nsintegernumberofcomponents;
Common methods of Uipickerview
// 重新刷新所有列- (void)reloadAllComponents;// 重新刷新第component列- (void)reloadComponent:(NSInteger)component;// 主动选中第component列的第row行- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;// 获得第component列的当前选中的行号- (NSInteger)selectedRowInComponent:(NSInteger)component;
Data source Method (Uipickerviewdatasource)
// 一共有多少列- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;// 第component列一共有多少行- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
Proxy method (Uipickerviewdelegate)
What is the width of column component?-(cgfloat)Pickerview:(uipickerview *)Pickerview widthforcomponent:(nsinteger)component;//What is the row height of column component?(cgfloat)Pickerview:(uipickerview *)Pickerview rowheightforcomponent:(nsinteger)component;//what text is displayed on row row of section component-(nsstring *)Pickerview:(uipickerview *)Pickerview Titleforrow:(nsinteger)Row forcomponent:(nsinteger)component;//section component, row row shows what view(content)-(UIView *)Pickerview:(uipickerview *)Pickerview Viewforrow:(nsinteger)Row forcomponent:(nsinteger)Component Reusingview:(UIView *)view;//the first row of column component of Pickerview is selected-(void)Pickerview:(uipickerview *)Pickerview Didselectrow:(nsinteger)Row incomponent:(nsinteger)Component
Note the point:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
The reuse view of this method is always empty after ios6. If you need to adapt the system before IOS6, for performance reasons, this view should be used.
Before iOS8, the height of the Uipickerview was (162) fixed and could not be modified. After the iOS8, its height can be modified.
The height of the Pickerview is set with note points:
If the height is not actively set, or set to 0. The height default value of 216
If the height of the setting is greater than 0 and less than 180, the height default value is 162
If the height of the setting is greater than or equal to 180 and less than 216, how high the default value is 180
Pickerview Width Setting:
When initialized without a given width, or a given width of 0, the width defaults to the width of the screen.
Given a width that is not greater than 0, the width is equal to the given value.
Uidatepicker
Uidatepicker Common Properties
// datePicker的显示模式@property (nonatomic) UIDatePickerMode datePickerMode;// 显示的区域语言@property (nonatomic, retain) NSLocale *locale;
The choice of listening Uidatepicker
- Because Uidatepicker inherits from Uicontrol, so through Addtarget: ... Listening
Code Creation Uidatepicker
//1. Create a date selectorUidatepicker *datepicker = [[Uidatepicker alloc] init];//2. Set the date display areaDatePicker. Locale= [Nslocale localewithlocaleidentifier:@"en"];//3. Set the date modeDatePicker. Datepickermode= Uidatepickermodetime;//4.0 set the minimum time (the first 20 years from the current time)DatePicker. Minimumdate= [NSDateDatewithtimeintervalsincenow:-(365* -*3600* -)];//4.1 Set the maximum time (20 years from the current time)DatePicker. Maximumdate= [NSDateDatewithtimeintervalsincenow:365* -*3600* -];//5. Set the time interval. (The interval should be divisible by 60)DatePicker. Minuteinterval=6;
Uipickerview in iOS development