UIPickerView如何隐藏黑线或阴影

2021-01-30  本文已影响0人  花卷爱吃草

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;
}
上一篇 下一篇

猜你喜欢

热点阅读