图像的NSArray和UIPickerView中的文本NSArray

时间:2016-10-25 07:43:08

标签: ios objective-c nsarray uipickerview

我正在尝试构建一个UIPicker视图,其中包含口袋妖怪的所有名称和图像。问题是我似乎无法将图像和文本放在同一行。最好的方法是什么?

foreach ($data['items'] as $key => $value) 
{
        $val1 = strtotime($value->sub_date);
        $value->sub_date =jdate('y-m-d H:i',$val1);

        if (isset($value->unsub_date)) 
        {
                $val2 = strtotime($value->unsub_date);
                $value->unsub_date =jdate('y-m-d H:i',$val2);
        }

        $val3 = strtotime($value->first_sub);
        $value->first_sub =jdate('y-m-d H:i',$val3);

}

2 个答案:

答案 0 :(得分:0)

创建一个UIView对象,并通过其方法将此UIView对象传递给UIPickerView。 使用下面给出的代码。

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UIView* newView;
    //Insert anything in this view object and that will be visible to the screen
    return newView;
}

答案 1 :(得分:0)

正如@Syed e Hussaini所说,你需要提供并查看保存图像和文本。请使用我的下面的代码来实现UIPickerView行中的文本和图像。

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"your image %@.png", (long)row]];
    UIImageView *temp = [[UIImageView alloc] initWithImage:img];
    temp.frame = CGRectMake(-70, 10, 60, 40);

    UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)];
    channelLabel.text = [NSString stringWithFormat:@"%@", [your array objectAtIndex:row]];
    channelLabel.textAlignment = UITextAlignmentLeft;
    channelLabel.backgroundColor = [UIColor clearColor];

    UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
    [tmpView insertSubview:temp atIndex:0];
    [tmpView insertSubview:channelLabel atIndex:1];

    return tmpView;
}