iOS开发之修改UIPickerView的间隔线颜色

#pragma mark - UIPickerViewDelegate
 - (nullable NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)componen {
    NSString *str = [self.dataArr objectAtIndex:row];
    NSAttributedString *attr = [[NSAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName:kTitleFont,NSForegroundColorAttributeName:kTitleColor}];
    
    //间隔线
    [self.pickerView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.frame.size.height < 1)
        {
           [obj setBackgroundColor:[UIColor orangeColor]];   //修改间隔线颜色

          //[obj setBackgroundColor:[UIColor clearColor]];    //隐藏间隔线
        }
    }];
    
    return attr;
}

你可能感兴趣的:(iOS开发之修改UIPickerView的间隔线颜色)