2013-05-16 66 views
0

我是iOS新手。我想在不同的按鈕操作中傳遞不同的圖像數組。我想重裝iCarousel在每一個按鈕動作如何將圖像數組傳遞給icarousel?如何重新加載圖像陣列數據重新加載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
- (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