Change UIPicker appearance

1.1k Views Asked by At

So I'm facing this problem, the standard UIPicker doesn't look good in my (proto) app and I would really change its appearance. I've already googled it and found this useful link http://aralbalkan.com/2985. Looks good but I'm wondering if there isn't an easier way to do it.

Here on stack overflow I've found this thread Is it possible to 're-skin' the IOS Date Picker?, it's "unsolved" but pointing to the first article.

I also did a tutorial in Apress Book "Beginning Iphone development" (chapter 7 I think), very useful, but there I was changing just the content of the columns, not the full appearance of it. Just to be clear, it would be great to have something like this:

enter image description here

Anyone has a good tutorial/link/suggestion for an Objective-c rookie? Thx in advice

EDIT: So I've implemented the method detailed in the two answers below and it works like a charm. But I'm still stuck with the background color ....

2

There are 2 best solutions below

3
On BEST ANSWER

the numbers shoud be able to create via using UIPickerViewDelegate's pickerView:viewForRow:forComponent:reusingView:, while the comma could be added via addSubView:.

or you go down another road and use a open source alternative, i.e. AFPickerView

You can manipulate teh views in the hierarchy — but probably it is easier to recreate the picker …

-(void)viewDidAppear:(BOOL)animated
{
    for (UIView *view in [self.pickerView subviews]) {
        NSLog(@"%@", view);
    }
    [(UIView *)[[self.pickerView subviews] objectAtIndex:1] setBackgroundColor:[UIColor blueColor]];
    [(UIView *)[[self.pickerView subviews] objectAtIndex:0] setHidden:YES];
    [(UIView *)[[self.pickerView subviews] lastObject] setHidden:YES];

    for (UIView *view in [(UIView *)[[self.pickerView subviews] objectAtIndex:2] subviews]) {
        NSLog(@"> %@", view);
    }

   [[[(UIView *)[[self.pickerView subviews] objectAtIndex:2] subviews] lastObject] setHidden:YES];
}
0
On

use the delegate of the UIPickerView. Create a method called

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

So at this point, you can create a UIView (or subclass). At this point, you have full control over what the view will display. You can change the background color and alpha. And if you subclass UIView, you can have your own drawing routines.