2013-04-17 63 views
3

我在我的iPad應用程序中使用iCarousel,我想知道是否有辦法在選擇時動態更改中心項目的視圖。總之,我想達到這樣的事情enter image description here 我設法設置第一個索引(項目 - 0)爲紅色,但我想不出辦法做到以下幾點:iCarousel - 更改中心項目動態iOS

當選擇1我希望將0的圖像更改爲純白色,將1更改爲紅色。

東西也是2。

任何幫助或建議,將不勝感激。

感謝

回答

12

如果您想選擇的項目,然後改變顏色,然後只是簡單地使用:

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

如果你想當前項目顏色是紅色的沒有選擇,那麼你需要做更多的事情:

- (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 
    } 
} 

,你也需要用這種方法來檢查指標變化與否:

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

如果我想改變顏色didSelectItemAtIndex,那麼我需要做的是什麼?我將如何獲得選定的視圖參考? –

+0

@AvijitDas您可能擁有一組自定義視圖作爲iCarousel的數據源。並且只需從customView [index]獲取參考?是您正在尋找的? – brianLikeApple

+0

謝謝呀我正在尋找訪問當前選擇的視圖的屬性。我在didSelectItemAtIndex函數下使用了currentItemView方法,並實現了我的目標。這裏是代碼ReflectionView * refelctionView =(ReflectionView *)self.carousel.currentItemView; –

0

iCarousel有一個委託方法

- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index 

,只要你選擇一個項目,指數爲您提供了當前所選項目的索引都會調用。您可以使用此索引更改視圖的顏色。你也可以將你以前的視圖的索引保存在任何整數變量中,並使用相同的方法重置該塊的顏色。