如何让我的UIPickerView在选定的值后显示标签?

如何让我的UIPickerView在选定的值后显示标签?

问题描述:

现在,选择器只显示正在选择的数据。我希望它在选定的值后面有一个词,就像iPhone时钟应用程序在选择器上有小时和min一样。

Right now, the selecter just shows the data being selected. I want it to have a word after the selected value, the same way the iPhone clock app has "hours" and "min" at the selector.

你必须自己使用下面的方法创建两个标签。这是pickerView的委托方法,当pickerview被加载或者它的reloadcomponent命令时,它会自动调用。

you have to create two labels by yourself using below method .This is the delegate method of pickerView which is automatically calls when the pickerview gets loaded or when its gets reloadcomponent command.

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

    UIView *pickerviewtemp=[[UIView alloc] initWithFrame:CGRectZero];

    UILabel *lbl=[[[UILabel alloc] initWithFrame:yourrequiredframe]autorelease];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setText:*set text according to yourself*];
    [lbl setFont:[UIFont boldSystemFontOfSize:16]];
    [pickerviewtemp addSubview:lbl];

    UILabel *lb2=[[[UILabel alloc] initWithFrame:yourrequiredframe]autorelease];
    [lbl2 setBackgroundColor:[UIColor clearColor]];
    [lbl2 setText:*set text according to yourself*];
    [lbl2 setFont:[UIFont boldSystemFontOfSize:16]];
    [pickerviewtemp addSubview:lbl2];


    return pickerviewtemp;
}