UIPickerView如何隐藏黑线或阴影

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。