I build my project in Xcode 8. UIPickerView separator lines are not visible in iOS 10 simulator and the devices, but works fine on iOS 9.3 devices and simulator. I tried to adjust the UIPickerView back ground color, auto layouts and everything possible in the XIB, but nothing works. Anyone have an idea on this?
This is a custom view which contains a 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;
}
I'm not sure what "separator lines" you are talking about. I don't see "separator lines" in iOS 9 either.
The only "lines" missing from your screen shot are the selection indicator. You can get them by setting the picker view's
showsSelectionIndicator
toYES
. But you shouldn't have to; showing the selection indicator is the default. The docs say:This is my code:
I had this exact issue when I rebuilt a couple of solutions for iOS10 and deployed to iOS10 on both simulators and devices.
I narrowed the problem in my case to be down to selecting an item in the picker during initialisation. ie. I populate my picker and if we have already got a selection for this property then I preselect it and the lines are present. I do this during the initialisation when I set up my picker.
So my fix, which worked in my use case, was to select the 0 element in the case of no existing value.
Objective-C
Swift
This was fine for my solution since I effectively select row zero on setup.
I haven't had chance to dig into the reasoning or look for a cleaner solution, but since I've solved my problem I thought I'd share it here to help you all out if I can.
add the code
[pickerView selectRow:0 inComponent:0 animated:YES];
before pickerView added to superView.Solved this problem using subclass of UIPickerView:
I am also facing the same issue. Below is my code for creating the UIPickerView: