iosobjective-cuipickerview

How to set background color of UIPickerView using UIAppearance?


I am using the following line of code to change the background color of UIPickerView throughout my app as it is for a theme in the app. This changes nothing.

 [[UIPickerView appearance] setBackgroundColor: [UIColor orangeColor]];

I also tried the following line but that give a weird shaded background that looks terrible.

[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIPickerView class]]] setBackgroundColor: [UIColor darkGrayColor]];

Here is an image of what the above line shows: enter image description here

I want the background color to be one solid color.

The question is, how can I change the background color of UIPickerView in the whole app using UIAppearance?


Solution

  • As per my Knowledge UIPicker does not conforms to UI_APPEARANCE_SELECTOR for UIAppereance ..

    [pickerView setBackgroundColor:[UIColor blueColor]];
    

    OR You Might want use..

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    

    Above two are the solutions i would prefer to change Picker Appearance..There although an other way to set an image, but i won't suggest to use that.

    Its up to you NOW..