UIPickerView 滚动选择器
2018-07-20 来源:open-open
/////别忘记 .h 中写代理 <UIPickerViewDelegate,UIPickerViewDataSource> /////UIPickerView和UIDatePicker是类似的控件,只不过UIDatePicker是日期控件,只能放日期,而UIPickerView可以放任何东西。 - (void)viewDidLoad { [super viewDidLoad]; _dataArray = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", @"d", @"e", @"f", nil]; UIPickerView* pv = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 460-216, 320, 216)]; pv.delegate = self; pv.dataSource = self; pv.showsSelectionIndicator = YES; [self.view addSubview:pv]; //[pv release]; } //多少组 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2; } //每一组多少行 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ if (component == 1) { return 3; } if (component == 0) { return _dataArray.count; } return 10; } //显示每一行的文本 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ if (component == 0) { return [_dataArray objectAtIndex:row]; } return [NSString stringWithFormat:@"%d",row]; } - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ //如果是第0组 if (component == 0) { //如果是第0组的第0行 if (row == 0) { //return 显示的view } if (row == 1) { // } } UIView* myview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; myview.backgroundColor = [UIColor redColor]; return myview; } //选择一行就会调用这个方法 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ NSLog(@"选择的是第%d组,第%d行",component,row); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:jsp 文件安全下载
最新资讯
热门推荐