1

在此处输入图像描述

-(UIView *)pickerView:(UIPickerView *)pickerView
           viewForRow:(NSInteger)row
         forComponent:(NSInteger)component reusingView:(UIView *)view
{
    //NSLog(@"%d",component);
   // NSLog(@"tag: %d",pickerView.tag);

    if([pickerView isEqual:picker1])

    {


        NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+1];
        NSArray *array1 = [self valueForKey:arrayName];
        UIImageView *imageView = [array1 objectAtIndex:row];
        if ([pickerView selectedRowInComponent:component] == row) {
            imageView.frame = CGRectMake(60,60,40,80);//set bigger frame
        } else {
            //imageView.frame = CGRectMake(30,30,20,60);//set normal frame
        }
        return imageView;
        }

}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 80.0;

}

我正在实现自定义 uipicker 以实现以下第一个图像。我要使用 uipicker 选择三个图像。但是,它们都显示在下面第二张图像的屏幕上。我只想在中间显示占据更大的尺寸,而不是如图所示的其他图像。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

1

更新:根据您的评论,您需要使中间行更大。

将您的 viewForRow 方法修改为,

- (UIView *)pickerView:(UIPickerView *)pickerView
           viewForRow:(NSInteger)row
         forComponent:(NSInteger)component reusingView:(UIView *)view
{
    //NSLog(@"%d",component);
    NSLog(@"tag: %d",pickerView.tag);

    if(pickerView.tag==1)
    {   NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+1];
        NSArray *array1 = [self valueForKey:arrayName];
        UIImageView *imageView = [array1 objectAtIndex:row];
        if ([pickerView selectedRowInComponent:component] == row) {
           imageView.frame = CGRectMake(..);//set bigger frame
        } else {
           imageView.frame = CGRectMake(..);//set normal frame
        }
        return imageView;
    }

实现pickerView:rowHeightForComponent:方法并为行设置合适的高度。

    - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {

为了隐藏选择指示器,设置showsSelectionIndicator的属性UIPickerView。有关更多详细信息,请查看苹果文档。

根据您的评论,

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
      [pickerView reloadComponent:component];
}
于 2012-11-27T00:12:15.370 回答
0

谁需要帮助!这是解决方案。所有学分都归@ACB!!!

-(UIView *)pickerView:(UIPickerView *)pickerView
               viewForRow:(NSInteger)row
             forComponent:(NSInteger)component reusingView:(UIView *)view
    {
        //NSLog(@"%d",component);
       // NSLog(@"tag: %d",pickerView.tag);

        if(pickerView.tag==1)

        {


            NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+1];
            NSArray *array1 = [self valueForKey:arrayName];
            UIImageView *imageView = [array1 objectAtIndex:row];
            if ([pickerView selectedRowInComponent:component] == row) {
                imageView.frame = CGRectMake(60,60,40,80);//set bigger frame
            } else {
                imageView.frame = CGRectMake(30,30,20,60);//set normal frame
            }
            return imageView;

            //NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+1];
            //NSArray *array1 = [self valueForKey:arrayName];
            //return [array1 objectAtIndex:row];
        }
        else if([pickerView isEqual:picker2])
        {
            NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+5];
            NSArray *array1 = [self valueForKey:arrayName];
            UIImageView *imageView = [array1 objectAtIndex:row];
            if ([pickerView selectedRowInComponent:component] == row) {
                imageView.frame = CGRectMake(60,60,40,80);//set bigger frame
            } else {
                imageView.frame = CGRectMake(30,30,20,60);//set normal frame
            }
            return imageView;


            /* NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+5];
            NSArray *array2 = [self valueForKey:arrayName];
            return [array2 objectAtIndex:row];*/
        }
        else
        {
            NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+9];
            NSArray *array1 = [self valueForKey:arrayName];
            UIImageView *imageView = [array1 objectAtIndex:row];
            if ([pickerView selectedRowInComponent:component] == row) {
                imageView.frame = CGRectMake(60,60,40,80);//set bigger frame
            } else {
                imageView.frame = CGRectMake(30,30,20,60);//set normal frame
            }
            return imageView;



           /* NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+9];
            NSArray *array3 = [self valueForKey:arrayName];
            return [array3 objectAtIndex:row];*/
        }

    }

    - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
    {
        return 120.0;

    }

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
        [pickerView reloadComponent:component];
    }
于 2012-11-27T02:11:26.353 回答