美文网首页
iOS开发之修改UIPickerView的间隔线颜色

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

作者: happycheng | 来源:发表于2019-07-24 16:05 被阅读0次
#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的间隔线颜色

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