滑动uicollectionview时,保持第一个可见的headerview的uilabel的textcolor = yellow

时间:2018-10-28 12:50:26

标签: ios objective-c uicollectionview

在滑动uicollectionview时,我要使uicollectionview的第一个可见标头视图的uilabel的颜色为黄色,而另一个可见标头视图为黑色。

我该如何实现?

1 个答案:

答案 0 :(得分:0)

问题已经完美解决,下面我上传了演示:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.CollectionView) {
//Calculate the section with contentOffset
        CGFloat contentOffset = scrollView.contentOffset.y;
        NSInteger lastSection = self.firstSection;
        if (contentOffset <= 0) {
            self.firstSection = 0;
        } else {
            for (NSInteger section = 0; section < self.playListArr.count - 1; section++) {
                contentOffset = contentOffset - (HEADER_VIEW_HEIGHT + (LINE_SPACING + CELL_HEIGHT) * ceil([(NSMutableArray *)self.playListArr[section] count] / 3.0) - LINE_SPACING);
                if (contentOffset <= 0 || section == self.playListArr.count - 1) {
//return the current first section:
                    self.firstSection = section;
                    break;
                }
            }
        }
}