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
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;
}
Here, I got proper answer for this question(I have did it for one component
change it as per your requirement) take a look:
you need to implement the method:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
//set your View. Here is an example ..
UIView *pickerviewtemp=[[UIView alloc] initWithFrame:CGRectZero];
UILabel *lbl=[[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]autorelease];
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setText:[array_from objectAtIndex:row]];
[lbl setFont:[UIFont boldSystemFontOfSize:16]];
[pickerviewtemp addSubview:lbl];
return pickerviewtemp;
}
Take a int
variable in .h
file named lastSelectedIndex
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
UILabel *label = (UILabel*)[pickerView viewWithTag:999+(component*lastSelectedIndex)]; // you can set your own tag...
[label removeFromSuperview];
UIView *view = [pickerView viewForRow:row forComponent:component];
UILabel *lbl2=[[[UILabel alloc] initWithFrame:CGRectMake(110, 0, 50, 50)]autorelease];
lbl2.tag = 999+(component*row);
[lbl2 setBackgroundColor:[UIColor clearColor]];
[lbl2 setText:@yourtext"];
[lbl2 setFont:[UIFont boldSystemFontOfSize:16]];
[view addSubview:lbl2];
lastSelectedIndex = row;
}
I have tested it. Hope it will help you.... :)
You will have to do a customized UIPickerView
In your case if what you need is just adding some labels, you could simply add to the UIPickerView
Two UILabel
over, because UIPickerView
is an UIView
... Quick but dirty...