如何将图像数组传递给icarousel?如何重新加载图像数组数据以重新加载icarousel?

时间:2013-05-16 06:10:17

标签: iphone ios6

我是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。

提前致谢..

1 个答案:

答案 0 :(得分: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;
}

输出:

enter image description here

enter image description here