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.
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
selectionIndicator@2x.png































Dec 07, 2012 @ 05:38:41
It is giving error in actionsheetPickerViewTemplates.How to resolve it
Dec 07, 2012 @ 08:05:53
What is the exact error message?
Dec 07, 2012 @ 10:42:00
actionsheetpickerviewtemplates undeclared.
Dec 07, 2012 @ 10:52:11
Did you do this in the .h file:
@property (nonatomic, strong) UIPickerView *actionsheetpickerviewtemplates;
And in the .m file
@synthesize actionsheetpickerviewtemplates;
?