Row Separator in UIPickerView

Viewed 9348

How do i hide the Separator in my Picker View.Here is the screenshot enter image description here.

Here is the code for my custom UIPickerView.

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

UILabel *label=[[UILabel alloc]init];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.textAlignment=NSTextAlignmentCenter;

switch (component) {
    case 0:
        label.text=[_hourArray objectAtIndex:row];
        label.font = [UIFont fontWithName:@"MYRIADPRO-REGULAR" size:70];
        break;

    case 1:
        label.text=[_minutesArray objectAtIndex:row];
        label.font = [UIFont fontWithName:@"MYRIADPRO-REGULAR" size:70];
        break;

    case 2:
        label.text=[_ampmArray objectAtIndex:row];
        label.font = [UIFont fontWithName:@"MYRIADPRO-REGULAR" size:15];

        break;

    default:
        break;
}
return label;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 3;
}

Please Help me out.Thanks

3 Answers

In Swift 5 you can use this workaround. Just add this code to your viewcontroller class:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    for i in 1...2 {
        myPickerView.subviews[i].isHidden = true
    }
}

If you really need, here is a pragmatic solution: Create a subclass of UIPickerView where you override didAddSubview. If the added subview has a height <= 1.0, then it's a separator and you can hide and/or remove it.

NOTE: Might break in future iOS versions, so handle with care.

Related