Search code examples
iosipadicarousel

iCarousel - Change center item Dynamically iOS


I am using iCarousel in my iPad application, i would like to know if there is way to change the view of the center item dynamically whenever selected. In short i would like to achieve something like thisenter image description here I managed to set the first index (item - 0) to red, but i could not figure out a way to do the following:

When 1 is selected i wish to change the image of 0 to plain white and 1 to red.

Something for 2 as well.

Any Help or Advise would be appreciated.

Thanks


Solution

  • If you want to select item and then change the colour then just simply use:

    - (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{
    //change the view of current index
    }
    

    If you want current item colour is red without select, then you need to do more things:

    - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
    //Here you need to check current index
        if (index == self.carousel.currentItemIndex) {
        //change the view
        }
    }
    

    And also you need to use this method to check index changed or not:

    - (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
    //you need to reload carousel for update view of current index
    [self.carousel reloadData];
    }