这个问题很容易解决,需要在pickerview的代理方法中设置上下横线的颜色就可以了
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(0, 0, _picker.frame.size.width, 32); label.font = [UIFont systemFontOfSize:22]; if (component == 0) { label.text = self.yearArray[row]; }else if (component == 1) { label.text = self.monthArray[row]; }else if (component == 2) { label.text = self.dayArray[row]; } label.textAlignment = NSTextAlignmentCenter; // 设置横线的颜色,实现显示或者隐藏 ((UILabel *)[_picker.subviews objectAtIndex:1]).backgroundColor = FINELINECOLOR; ((UILabel *)[_picker.subviews objectAtIndex:2]).backgroundColor = FINELINECOLOR; return label; }
时间: 2024-10-05 05:31:39