2

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 ....

Community
  • 1
  • 1
Sr.Richie
  • 5,680
  • 5
  • 38
  • 62

2 Answers2

1

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];
}
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • I implemented your method and I'm having now custom views for my picker, thanx :) Now I'm struggling against background color.... any hint? – Sr.Richie May 24 '12 at 21:23
  • see my edit for a way, but this way is dangerous, as it might break with new reales of iOS. – vikingosegundo May 24 '12 at 21:44
  • thx again. I'm testing right now AFPickerView, I tested your code and I think that to implement it the way I would, it would be probably too hard for my n00b level :) – Sr.Richie May 24 '12 at 22:17
1

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.

John
  • 116
  • 1