* NSObject
* UIResponder
* UIView
* UIPickerView
UIPickerView只有三个高度, heights for UIPickerView (162.0, 180.0 and 216.0)
- (NSInteger)numberOfRowsInComponent:(NSInteger)component
组件的行数,默认值为0
- (CGSize)rowSizeForComponent:(NSInteger)component
组件的行大小(宽高)
- (CGFloat)pickerView:(UIPickerView *)pickerView
widthForComponent:(NSInteger)component
组件的行宽
- (CGFloat)pickerView:(UIPickerView *)pickerView
rowHeightForComponent:(NSInteger)component
组件的行高
- (void)reloadAllComponents
重新加载所有组件的数据
- (void)reloadComponent:(NSInteger)component
重新加载指定组件的数据
- (void)selectRow:(NSInteger)row
inComponent:(NSInteger)component
animated:(BOOL)animated
选中某组件一行时的效果
- (NSInteger)selectedRowInComponent:(NSInteger)component
组件选中的行,如果没有选中,返回-1
- (UIView *)viewForRow:(NSInteger)row
forComponent:(NSInteger)component
组件每行的视图,若指定行不可见或代理没有执行,返回0
@property(nonatomic) BOOL showsSelectionIndicator
是否显示指定行
delegate方法
//设置列宽和行高
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
//设置行标题
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
//
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:
(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0); // attributed title is favored if both methods are implemented
//设置行视图
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
//选中行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
datasource方法
// 显示的行数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 特定组件返回的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
iOS UIPickerView
最新推荐文章于 2021-04-09 15:01:13 发布