UIPickView和UIDatePicker

UIPickView和UIDatePicker UIPickView 样式
UIPickView和UIDatePicker
文章图片
Paste_Image.png 作用

- 通常用在注册,比如选择城市 - 老虎机效果

常见用法
- 独立,没有任何关系 -》菜单系统 - 相关联的,下一列和第一列有联系 -》城市选择 - 图文并帽 -》国旗

注意
- 如何得到选中的某一行 `[self.pickerView selectRow:row inComponent:componen animated:YES]; ` - 调用pickView滚动不会触发代理,只有用户手动滚动才能触发

显示数据
- 实现数据源和代理方法 - UIPickView数据源方法

#pragma mark /** *返回多少列 */ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; /** *返回第component列有多少行 */ - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; -

- UIPickView代理方法

#pragma mark /* *返回第component列第row行的展示样式*/ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; /* *返回第component列第row行带属性的标题*/ - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component ; /* *返回第component列第row行展示视图*/ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view; /* *选中第component列第row行调用*/ - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; /* *返回第component列每一行的宽度*/ - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component; /* *返回第component列每一行的高度*/ - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;

UIDatePicker 样式
UIPickView和UIDatePicker
文章图片
Paste_Image.png

    推荐阅读