UIPickerView *pickView = [[UIPickerView alloc]init];
/*协议·
* UIPickerViewDelegate
* UIPickerViewDataSource
*/
pickView.delegate = self;
pickView.dataSource = self;
pragma mark - pickView-->dataSource & delegate
/*/*pickView返回的列数
*参数表示遵循代理协议的pickView
*/
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 3;
}
/*表示每一列有多少行
*参数1:表示遵循协议代理的pickView
*参数2:表示列数
*/
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return 10;
}
//每一行的内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return @"";
}
//设置每一行的高度
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
return 7;
}
//设置每一列中行的高度,实际都显示最高列的高度
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
return (component+1)*30;
}
//监控选中的行数和列数
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = [[UILabel alloc]init];
return label;
}
</code>
网友评论