UIPickerViewselect指示器在iOS10中不可见

我在Xcode 8中构build项目。UIPickerView分隔线在iOS 10模拟器和设备中不可见,但在iOS 9.3设备和模拟器上正常工作。 我试图调整UIPickerView背景颜色,自动布局和XIB中的所有可能,但没有任何工作。 任何人有这个想法?

这是一个包含UIPickerView的自定义视图

在这里输入图像说明

-(void)layoutSubviews{ isShown = NO; [super layoutSubviews]; //self.selectedDic = nil; self.doneBtn.tintColor = COLOR_DB3535; self.pickerView.backgroundColor = COLOR_DEDEDE; self.pickerView.showsSelectionIndicator = YES; [self.doneBtn setTitle:NSLocalizedString(@"App_Generic_Button_Text_Done", @"")]; } -(UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; label.tintColor = [UIColor clearColor]; label.backgroundColor = [UIColor yellowColor]; label.textColor = COLOR_666; label.font = [FontsManager getFONT_ROBOTO_LIGHT_16]; label.textAlignment = NSTextAlignmentCenter; NSDictionary *dict = [dataArray objectAtIndex:row]; label.text = @"Test"; return label; } 

当我为iOS10重build了几个解决scheme并在模拟器和设备上部署到iOS10时,我遇到了这个问题。

在我的情况下,我缩小了问题的范围,以便在初始化期间select拾取器中的项目。 即。 我填充我的select器,如果我们已经有了这个属性的select,那么我预先select它,并存在行。 我在初始化过程中,当我设置我的select器时这样做。

所以我的解决scheme,在我的用例,是在没有现有值的情况下select0元素。

Objective-C的

 UIPickerView *pickerView; ... [pickerView selectRow:0 inComponent:0 animated:YES]; 

迅速

 let pickerView: UIPickerView ... pickerView.selectRow(0, inComponent: 0, animated: true) 

这对我的解决scheme来说很好,因为我在安装时有效地select了第零行。

我没有机会深入推理或寻求更清晰的解决scheme,但是由于我已经解决了我的问题,所以我想我会在这里分享,如果可以的话,帮助大家。

 UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 200)]; pickerView.backgroundColor = [UIColor whiteColor]; pickerView.dataSource = self; pickerView.delegate = self; [pickerView selectRow:0 inComponent:0 animated:YES]; [self.view addSubview:pickerView]; 

添加代码[pickerView selectRow:0 inComponent:0 animated:YES]; pickerView添加到superView之前。

我也在iOS10中遇到了同样的问题。 这是我的问题: 在这里输入图像说明

我解决了这个问题:

  self.pickerView.backgroundColor = COLOR_DEDEDE; self.pickerView.showsSelectionIndicator = YES; for (UIView *view in self.pickerView.subviews) { if (view.bounds.size.height < 2.0f && view.backgroundColor == nil) { view.backgroundColor = PICK_Line_COLOR; // line color } } 

注意:

这个代码在调用方法之后调用: [self.view addSubview:pickeView];

最终的结果是:

在这里输入图像说明

它在我的项目中工作。 希望对你有所帮助。

我不确定你在说什么“分隔线”。 我没有看到iOS 9中的“分隔线”。

屏幕截图中仅有的“线条”是select指示符。 您可以通过将选取器视图的showsSelectionIndicatorYES来获取它们。 但是你不应该 显示select指示符是默认的。 文档说:

在iOS 7及更高版本中…总是显示select指示符

在这里输入图像说明

这是我的代码:

 -(UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ for(UIView *single in pickerView.subviews) { if (single.frame.size.height < 1) { single.backgroundColor = [UIColor grayColor]; } } //other code } 

我也面临同样的问题。 下面是我创buildUIPickerView的代码:

 self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, frame.size.height - 216, frame.size.width, 216)]; self.pickerView.dataSource = self; self.pickerView.delegate = self; self.pickerView.backgroundColor = [UIColor whiteColor]; self.pickerView.showsSelectionIndicator = YES; [self addSubview:self.pickerView];