Custom UIPickerView selectionIndicator 4

For one of my apps, I wanted to change the color of the selectionIndicator on the UIPickerView. Apparently, there isn’t a simple tintColor available for this (yet). I did look into subclassing the UIPickerView for a moment, but then I decided to go for the easy and simple solution of creating my own selectionIndicator and placing it on top of the UIPickerView.

 

UIPickerView Custom selectionIndicator

 

Code:
// CGRectMake values for the frame we’d like
myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height)];
// add the UIPickerView to your viewcontroller, actionsheet, …
[mainView addSubview:myPickerView];

// set the selectionindicator to none
myPickerView.showsSelectionIndicator = NO;
// define the image that we would like to use
UIImage *selectorImage = [UIImage imageNamed:@"selectionIndicator.png"];
UIView *customSelector = [[UIImageView alloc] initWithImage:selectorImage];
// set the x and y values to the point on the UIPickerView where you want to place the image
// set the width and height values to the width and height of your image
customSelector.frame = CGRectMake(10,(myPickerView.bounds.size.height / 2) + 16, self.view.bounds.size.width – 10, 47);
// add the custom selectionIndicator also to the same viewcontroller, actionsheet, …
[mainView addSubview:customSelector];

 

selectionIndicator.png

UIPickerView custom selectionIndicator image

selectionIndicator@2x.png

UIPickerView custom selectionIndicator image