IOS7 UIPickerView how to hide the selection indicator
[[pickerview.subviews objectAtIndex:1] setHidden:TRUE];[[pickerview.subviews objectAtIndex:2] setHidden:TRUE];
Use this in titleForRow
or viewForRow
delegate method of the pickerView
.
Based on the other answers, I decided to enumerate the subviews and saw that the lines have a height of 0.5
so my solution now looks like this in Swift:
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { pickerView.subviews.forEach({ $0.hidden = $0.frame.height < 1.0 }) return myRowCount}
And in Objective-C
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { [pickerView.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { subview.hidden = (CGRectGetHeight(subview.frame) < 1.0) }]; return myRowCount}
Obviously not particularly future proof, but probably more so than hiding a subview at a given index.
Edit: Updated to handle the case provided by @Loris
In iOS7 setting the parameter pickerview.showsSelectionIndicator has no effect, according to the documentation (https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UIPickerView.html).
However, as a UIPickerView in the end is a UIView with subviews, I checked what subviews there were. I found 3, the first one contained all the components of the UIPickerView, and the other two are the two lines.
So by setting the second and third (index 1 and 2) hidden, the two lines were removed.
[[pickerview.subviews objectAtIndex:1] setHidden:TRUE];[[pickerview.subviews objectAtIndex:2] setHidden:TRUE];
It's not a real nice solution, and definitely not forward compatible, but for now it gets the job done. Hope this helps.