How can I make my UIPickerView show labels after the selected value?

后端 未结 3 1101
心在旅途
心在旅途 2021-01-03 23:44

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\" a

3条回答
  •  暖寄归人
    2021-01-04 00:25

    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;
    }
    

提交回复
热议问题