Bernardo O
Bernardo O

Reputation: 828

Removing UIPickerView Blue Highlight

For some time now I've been trying to remove the blue highlight in UIPickerView when you're using the pickerView:viewForRow:forComponent:reusingView: delegate.

I'm sure many here have been there and wanted to remove that ugly blue highlight in the UIPickerView.

The UIPickerView has a UITableView - rather a UIPickerTable inside which has cells where your UILabels/UIViews/UIImageViews or whatever lay. Logically, if it's a tableview, then we can just access the cell and setSelectionStyle:UITableViewCellSelectionStyleNone right? Wrong.

UIPickerTable is a private class of the API and does not allow you to set anything in there.

I've managed to get all the subviews in my picker

[[myPickerView subviews] objectAtIndex:someIndexValue];

So I tried this in pickerView:didSelectRow: and pickerView:viewForRow:

NSIndexPath *path = [[[myPickerView subviews] objectAtIndex:5] indexPathForSelectedRow];
[[[[myPickerView subviews] objectAtIndex:5] cellForRowAtIndexPath:path] setSelectionStyle:UITableViewCellSelectionStyleNone];

And this:

[[[myPickerView subviews] objectAtIndex:5] setSelectionStyle:UITableViewCellSelectionStyleNone];

None of them worked 'cause it's private. Giving me this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPickerTable setSelectionStyle:]: unrecognized selector sent to instance 0x64479a0'

I know about setting the view's frame to the size of the pickerView:rowHeightForComponent: and then doing:

label.UserInteractionEnabled = YES;

Before returning it on pickerView:viewForRow method.

But it doesn't really remove the highlight, it just covers it and removes the UIPickerView's ability to autoscroll when some item is just clicked.

Does anyone know how can I remove this blue highlight from an UIPickerView with an UILabel/UIView/UIImageView inside?

I'm NOT talking about the selectionIndicator. This is the highlight that appears when you click an image inside the pickerView:

alt text

PS: This pickerView has NO selectionIndicator and is customized. However, the customization has nothing to do with the issue. This issue is simply for the fact that there's an object that inherits form UIView inside the picker's cell and viewForRow is being used.

Upvotes: 2

Views: 2158

Answers (1)

raaz
raaz

Reputation: 12500

How about Overriding highlighted selection in UIPickerView

Upvotes: 0

Related Questions