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 回答