11

I have created a sample picker-view which will display some details. Setting the Background color using:

_pickerView.backgroundColor = [UIColor redColor]; 

doesn't seems to be working . But I wish I could create a picker view like the below image

enter image description here

What I was trying to do is , the entire PickerView background color should not be white, it should fill with the UIColor which I am giving. Is that possible?? How it can be done ??

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Perseus
  • 1,546
  • 4
  • 30
  • 55
  • you want to change picker selected color or the color of whole bg ? – PJR Jul 11 '12 at 05:44
  • I want to change the Whole BG color which is white now. Even the selected color (but let me do the BG first later I will change the selected color too) – Perseus Jul 11 '12 at 05:49
  • check out the posted link will solve your issue. – Kuldeep Aug 04 '12 at 10:52
  • @Perseus: you can check out my answer. and check the last link which is exactly same as you are asking for... – DShah Aug 06 '12 at 11:29

6 Answers6

26

Addition to Nina's answer, below are some of the good custom Picker view controls which will be good to use in terms of performance and customizable.

  1. http://www.cocoacontrols.com/platforms/ios/controls/cppickerview
  2. http://www.cocoacontrols.com/platforms/ios/controls/afpickerview
  3. http://www.cocoacontrols.com/platforms/ios/controls/v8horizontalpickerview (Horizontal PickerView)
DShah
  • 9,768
  • 11
  • 71
  • 127
2

I wrote a custom picker view that uses a UITableView as it's starting point. Feel free to customize it however you want.

https://github.com/derekju/DjuPickerView

Derek Ju
  • 21
  • 1
1

You can change selected color by putting tableview cell in it.

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UITableViewCell *cell = (UITableViewCell *)view;

if( cell == nil ) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    [cell setBackgroundColor:[UIColor redColor]];

    [cell setBounds: CGRectMake(0, 0, cell.frame.size.width -20 , 44)];
    cell.textLabel.text = [self.userNameArray objectAtIndex:row];
    cell.userInteractionEnabled = NO;
}

return cell;
}
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
PJR
  • 13,052
  • 13
  • 64
  • 104
  • 1
    No No. This changes the redcolor to the no. of items present in the UIPicker. If I scroll down. At the end , I can see that , white color is coming.I want to change only full BG color of UIPickerView, which is white now. – Perseus Jul 11 '12 at 06:07
  • look at this answer http://stackoverflow.com/questions/965375/change-uipickerview-background – PJR Jul 11 '12 at 06:10
  • http://stackoverflow.com/questions/1968288/how-to-change-the-background-color-in-uipickerview – PJR Jul 11 '12 at 06:10
1

It is hard to customize a UIPickerView.

You might opt to use it in its default appearance or trying to simulate a UIPickerView using another UIKit component such as UITableView. There are some libs that are using UITableView to simulate a more flexible UIPickerView.

0

UIPickerView has subviews. Assigning an image to a view and adding it to the subview at index 2, would change the background of pickerview.

I had had a same kinda problem :-) See my question here!! Customize UIPickerView's Skin with images

Or you can use AFPickerView

Community
  • 1
  • 1
Nina
  • 1,579
  • 2
  • 21
  • 51
0

The API does not provide a way to change the style and color of selection dialer. You can change only inner view of the picker how u want to design. As the UIPickerView don't have the UI_APPEARANCE_SELECTOR.

Check out below link will help you out. Custom iOS UIDatepicker using UIAppearance

Community
  • 1
  • 1
Kuldeep
  • 2,589
  • 1
  • 18
  • 28