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

4

2 回答 2

1

数字应该能够通过 using UIPickerViewDelegate's创建pickerView:viewForRow:forComponent:reusingView:,而逗号可以通过addSubView:.

或者你走另一条路并使用开源替代品,即AFPickerView

您可以在层次结构中操作视图 - 但重新创建选择器可能更容易......</p>

-(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];
}
于 2012-05-24T15:39:09.117 回答
1

使用 UIPickerView 的委托。创建一个名为的方法

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

所以此时,您可以创建一个 UIView(或子类)。此时,您可以完全控制视图的显示内容。您可以更改背景颜色和 alpha。如果你继承 UIView,你可以拥有自己的绘图例程。

于 2012-05-24T16:23:16.410 回答