How to achieve picker view like this? I have implemented all necessary delegate and dataSource methods to populate the data, but the thing I am not able to understand is how to add this titles adults, children and infants? They are static and does not spin with the component!
-
Check out macttrek's answer [in this related question](http://stackoverflow.com/a/8524522/981049) and don't forget to upvote it if it helps you out! – Michael Dautermann Feb 07 '13 at 07:05
5 Answers
You could put the labels on a particular frame position and then make the labels background color as clearColor.

- 229
- 2
- 14

- 17,226
- 9
- 43
- 70
Add the 3 labels to your view as subviews when you showing the picker view and then hiding them when the picker is dismissed.
You will have to position the labels on the band.

- 131
- 1
- 6
-
1Why do you need to hide the labels? If they are sub views of the picker then there is no need for this. – rmaddy Feb 07 '13 at 14:51
I got this done just using Interface Builder.
I created a container view and then put picker view inside it. To be sure that my container size is the same as picker view I set space constraints: leading, trailing, top and bottom.
Then I put 3 labels above picker view (but they're still the subviews of the container) and set their frames to center it.
Also to achieve the same label visual effect as on the screenshot (it seems to be under selection bar) decrease label's alpha to about 0.7.

- 21
- 3
You need to add labels as subviews of the picker view. There is no functionality built into UIPickerView to make this easy.

- 314,917
- 42
- 532
- 579
-
I am trying this, what happes is those labels are showing in background, I mean behind the picker, I can see some part of my label between the components! – Hardik Thakkar Feb 07 '13 at 10:12
Create your picker, create a label with a shadow, and push it to a picker's subview below the selectionIndicator view.
It would look something like this
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(135, 93, 80, 30)] autorelease];
label.text = @"Label";
label.font = [UIFont boldSystemFontOfSize:20];
label.backgroundColor = [UIColor clearColor];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake (0,1);
[picker insertSubview:label aboveSubview:[picker.subviews objectAtIndex:5]];
//When you have multiple components (sections)...
//you will need to find which subview you need to actually get under
//so experiment with that 'objectAtIndex:5'
//
//you can do something like the following to find the view to get on top of
// define @class UIPickerTable;
// NSMutableArray *tables = [[NSMutableArray alloc] init];
// for (id i in picker.subviews) if([i isKindOfClass:[UIPickerTable class]]) [tables addObject:i];
// etc...

- 239
- 3
- 15
-
Please refer this link may helpfull http://stackoverflow.com/questions/367471/fixed-labels-in-the-selection-bar-of-a-uipickerview – vishnu Feb 07 '13 at 07:10