6

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

iYousafzai
  • 1,021
  • 1
  • 10
  • 29
  • try this http://stackoverflow.com/a/11451471/887325 – Bimawa Dec 12 '13 at 17:41
  • Similar question was asked here (http://stackoverflow.com/questions/20612279/uipickerview-how-to-hide-the-selection-indicator). Bimawa's link is useful. I tried that approach and it worked. – morksinaanab Jan 05 '14 at 04:24

3 Answers3

5

To hide the selection indicator for a UIPickerView:

_pickerView.showsSelectionIndicator = FALSE;

You can make it in code (as above) or in Interface Builder:

enter image description here

Edit

According to Apple documentation:

On iOS 7 and later you cannot customzie the picker view’s selection indicator. The selection indicator is always shown, so setting this property to NO has no effect.

Imanou Petit
  • 89,880
  • 29
  • 256
  • 218
Fabio
  • 1,757
  • 19
  • 33
-1

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
    }
}
Marco Boerner
  • 1,243
  • 1
  • 11
  • 34
-2

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
DrMickeyLauer
  • 4,455
  • 3
  • 31
  • 67