UIPickerView

  • 返回UIPickerView当前的列数
@property(nonatomic,readonly) NSInteger numberOfComponents; 

  • 返回component中一行的尺寸。
-  (CGSize)rowSizeForComponent:(NSInteger)component ;

  • 每列宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 
  • 显示数据的行高
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component

返回UIPickView每行显示的内容
// 设置UIPickView每行显示的内容
 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

// 返回一个视图,用来设置pickerView的每行显示的内容。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

注意:这两个方法是有冲突的,使用时一般只会用其中的一个方法
选中UIPickerView的某一列中某一行的时候 并且 停止滚动,就会调用这个方法
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

刷新数据
- (void)reloadComponent:(NSInteger)component;//刷新某一列的数据
- (void)reloadAllComponents;//刷新所有列的数据
返回选中的是第component列的第几行。
- (NSInteger)selectedRowInComponent:(NSInteger)component;    

在代码指定要选择的某component的某row
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; 
注:参数一选中默认值在选择器的位置的行数
参数二选中默认值在选择器的位置的组件索引
参数三是否设置过度动画   

在这个- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view代理方法里添加以下代码隐藏上下的黑线或者改变其颜色
//隐藏
[[pickerView.subviews objectAtIndex:1] setHidden:YES]; 
[[pickerView.subviews objectAtIndex:2] setHidden:YES];
//改变颜色
 [[pickerView.subviews objectAtIndex:1] setBackgroundColor:[UIColor redColor]];
 [[pickerView.subviews objectAtIndex:2] setBackgroundColor:[UIColor redColor]];

你可能感兴趣的:(UIPickerView)