如何让我的UIPickerView在选定的值后显示标签? [英] How can I make my UIPickerView show labels after the selected value?

查看:100
本文介绍了如何让我的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;
}

这篇关于如何让我的UIPickerView在选定的值后显示标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆