I also needed to set up a selection indicator, because I populate the collector with custom views (they look like cells in a table view) that are higher than the standard indicator.
My initial attempt to specify the translucent view to be overlaid on the UIPickerView when created led to the same result. During tracking, I noticed that there were no impressions in the selection view at the time of creation, which is probably the reason that the custom selection indicator will be sent to the back of the visual hierarchy.
My solution consists of specifying a custom view for the selection indicator when the delegate method is first selected pickerView: viewForRow: forComponent: is called reusingView :. At this point, UIPickerView is ready with all its subzones, and my new custom view is correctly added on top of the rest. If you donβt need to use custom views for content, you can do the same using another pickerView: titleForRow: forComponent: data source method.
The following snippet shows my solution.
Notes: if the delegate method serves more than one UIPickerView, you need to handle the flag differently; SLPickerCell is my own cell class, just a subclass of UIView.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { SLPickerCell *pickerCell = nil; NSArray *topLevelObjects; const CGFloat kPickerBorderSize = 10; const CGFloat kIndicatorVerticalMargin = 2;
source share