0

私はiOSが初めてです。異なるボタン アクションで異なる画像配列を渡したい。すべてのボタン アクションで iCarousel をリロードしたい

これが私のコードです

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
   UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",index]]];
   view.tag=index;
   view.frame = CGRectMake(70, 80, 180, 260);
   return view;
}

現在、このように画像をicarouselに渡しています。

前もって感謝します..

4

1 に答える 1

1
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [self.aryImages count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UIView *viewForImages = (UIButton *)view;
    if (viewForImages == nil)
    {
        UIImage *image = [UIImage imageNamed:[self.aryImages objectAtIndex:index]];
        viewForImages = [[UIView  alloc]init];
        viewForImages.frame = imagesFrameLocal;
        [viewForImages setBackgroundColor:[UIColor clearColor]];
        UIView *viewCreation = [[UIView alloc]initWithFrame:viewForImages.frame];
        [viewCreation setBackgroundColor:[UIColor whiteColor]];
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(viewForImages.bounds.origin.x+5, viewForImages.bounds.origin.y+5, viewForImages.bounds.size.width-10, viewForImages.bounds.size.height-10)];

        [btn setTag:index];
        if(onlineImages == YES)
        {
            [btn setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[self.aryImages objectAtIndex:index]]] placeholderImage:[UIImage imageNamed:@"1.png"]];
        }
        else
        {
            [btn setBackgroundImage:image forState:UIControlStateNormal];
        }
        [btn addTarget:self.recievedDelegate action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
        [viewCreation addSubview:btn];
        switch (index%5)
        {
            case 0:
                [viewCreation setTransform:CGAffineTransformMakeRotation(3)];
                break;
            case 1:
                [viewCreation setTransform:CGAffineTransformMakeRotation(19)];
                break;
            case 2:
                [viewCreation setTransform:CGAffineTransformMakeRotation(3)];
                break;
            case 3:
                [viewCreation setTransform:CGAffineTransformMakeRotation(19)];
                break;
            case 4:
                [viewCreation setTransform:CGAffineTransformMakeRotation(3)];
                break;
            default:
                [viewCreation setTransform:CGAffineTransformMakeRotation(19)];
                break;
        }
        [viewCreation.layer setCornerRadius:15.0f];
        [viewForImages addSubview:viewCreation];
    }
    return viewForImages;
}

出力::

ここに画像の説明を入力

ここに画像の説明を入力

于 2013-05-16T06:15:17.847 に答える