iOS pickerView和datePicker选择的分隔线有
2018-03-12 本文已影响3人
TIGER_XXXX
UIPickerView
UIPickerView操作分隔线需要在代理方法中操作
//隐藏分割线
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
((UILabel *)[pickerView.subviews objectAtIndex:1]).hidden = YES;//隐藏分隔线
((UILabel *)[pickerView.subviews objectAtIndex:2]).hidden = YES;//隐藏分隔线
return _items[row];
}
//显示分隔线
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
((UILabel *)[pickerView.subviews objectAtIndex:1]).backgroundColor = color;//显示分隔线
((UILabel *)[pickerView.subviews objectAtIndex:2]).backgroundColor = color;//显示分隔线
return _items[row];
}
UIDatePicker
UIDatePicker可以调用下面方法来操作
//隐藏分割线
- (void)clearSpearatorLine {
for (UIView *subView in self.datePicker.subviews) {
if ([subView isKindOfClass:[UIPickerView class]]) {
for (UIView *subView2 in subView.subviews) {
if (subView2.frame.size.height < 1) {//取出分割线view
subView2.hidden = YES;//隐藏分割线
}
}
}
}
}
//隐藏分割线
- (void)clearSpearatorLine {
for (UIView *subView in self.datePicker.subviews) {
if ([subView isKindOfClass:[UIPickerView class]]) {
for (UIView *subView2 in subView.subviews) {
if (subView2.frame.size.height < 1) {//取出分割线view
subView2.backgroundColor = color;//显示分割线
}
}
}
}
}