美文网首页
UIPickerView如何隐藏黑线或阴影

UIPickerView如何隐藏黑线或阴影

作者: 花卷爱吃草 | 来源:发表于2021-01-30 12:38 被阅读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;
}

相关文章

网友评论

      本文标题:UIPickerView如何隐藏黑线或阴影

      本文链接:https://www.haomeiwen.com/subject/junhtltx.html