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 で選択する 3 つの画像があります。ただし、それらはすべて、下の 2 番目の画像の画面に表示されています。表示されている画像のように、他の画像よりも大きなサイズを占める中央の画像のみが必要です。

ここに画像の説明を入力

ここに画像の説明を入力

ここに画像の説明を入力

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 に答える