iOS14以前,UIPickerView选中项有上下两条黑线,iOS14以后有选中项阴影,如何找到这两条黑线和阴影呢?
在pickerView的代理方法里找到:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *pickerLabel = (UILabel *)view;
if (!pickerLabel) {
pickerLabel = [[UILabel alloc] init];
pickerLabel.textColor = [UIColor colorWithHexString:self.textColor];
pickerLabel.adjustsFontSizeToFitWidth = YES;
[pickerLabel setTextAlignment:NSTextAlignmentCenter];
[pickerLabel setBackgroundColor:[UIColor clearColor]];
pickerLabel.font = [UIFont systemFontOfSize:self.fontSize];
}
pickerLabel.text = [self pickerView:pickerView titleForRow:row forComponent:component];
//iOS14以上只有1个subview,便是阴影
//iOS14以下有2个subview,便是那两条黑线
if (pickerView.subviews.count > 1) {
[[pickerView.subviews objectAtIndex:1] setHidden:TRUE];
}
if (pickerView.subviews.count > 2) {
[[pickerView.subviews objectAtIndex:2] setHidden:TRUE];
}
return pickerLabel;
}