Etiquetas fijas en la barra de selección de un UIPickerView

En la aplicación de relojes, la pantalla del temporizador muestra un selector (probablemente unUIPicker enUIDatePickerModeCountDownTimer modo) con texto en la barra de selección ("horas" y "minutos" en este caso).

(editar) Tenga en cuenta que estas etiquetas sonfijo: No se mueven cuando la rueda del selector está rodando.

¿Hay alguna manera de mostrar esas etiquetas fijas en la barra de selección de un estándarUIPickerView ¿componente?

No encontré ninguna API que me ayudara con eso. Una sugerencia fue agregar unUILabel como una subvista del selector, pero eso no funcionó.

Responder

Seguí el consejo de Ed Marty (respuesta a continuación), ¡y funciona! No es perfecto, pero debería engañar a la gente. Como referencia, aquí está mi implementación, siéntase libre de mejorarla ...

- (void)viewDidLoad {
    // Add pickerView
    self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
    [pickerView release];
    CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];
    CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
    #define toolbarHeight           40.0
    CGFloat pickerTop = screenRect.size.height - toolbarHeight - pickerSize.height;
    CGRect pickerRect = CGRectMake(0.0, pickerTop, pickerSize.width, pickerSize.height);
    pickerView.frame = pickerRect;

    // Add label on top of pickerView
    CGFloat top = pickerTop + 2;
    CGFloat height = pickerSize.height - 2;
    [self addPickerLabel:@"x" rightX:123.0 top:top height:height];
    [self addPickerLabel:@"y" rightX:183.0 top:top height:height];
    //...
}

- (void)addPickerLabel:(NSString *)labelString rightX:(CGFloat)rightX top:(CGFloat)top height:(CGFloat)height {
#define PICKER_LABEL_FONT_SIZE 18
#define PICKER_LABEL_ALPHA 0.7
    UIFont *font = [UIFont boldSystemFontOfSize:PICKER_LABEL_FONT_SIZE];
    CGFloat x = rightX - [labelString sizeWithFont:font].width;

    // White label 1 pixel below, to simulate embossing.
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, top + 1, rightX, height)];
    label.text = labelString;
    label.font = font;
    label.textColor = [UIColor whiteColor];
    label.backgroundColor = [UIColor clearColor];
    label.opaque = NO;
    label.alpha = PICKER_LABEL_ALPHA;
    [self.view addSubview:label];
    [label release];

    // Actual label.
    label = [[UILabel alloc] initWithFrame:CGRectMake(x, top, rightX, height)];
    label.text = labelString;
    label.font = font;
    label.backgroundColor = [UIColor clearColor];
    label.opaque = NO;
    label.alpha = PICKER_LABEL_ALPHA;
    [self.view addSubview:label];
    [label release];
}

Respuestas a la pregunta(7)

Su respuesta a la pregunta