Вопрос

Я создал CollectionView, который имеет разные данные в каждом столбце.Но чтобы отделить их, мне нужно добавить заголовок.Я могу добавить только один заголовок.Мой код для этого есть:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{

    UICollectionReusableView *reusableview = nil;
     UILabel *lblHeader;
    if (kind == UICollectionElementKindSectionHeader) {
        RePrecioHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CollectionHeaderView" forIndexPath:indexPath];
        NSArray *cellsInSection = self.ClassesArr[indexPath.section];

        float collectionWidth = self.view.bounds.size.width;

        int cellsInSectionCount = cellsInSection.count;

        float cellWidth = (collectionWidth) / cellsInSectionCount;
        cellWidth -= 10* (cellsInSectionCount -1);

        for(int i=0;i<self.ClassesArr.count; i++){


            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(85/self.ClassesArr.count,-5, cellWidth, 40)];
            view.backgroundColor = [UIColor grayColor];


            UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 14)];
            lbl.textColor = [UIColor whiteColor];
            lbl.font = [UIFont systemFontOfSize:12.0f];
            lbl.backgroundColor = [UIColor clearColor];
            lbl.text = [[[self.ClassesArr objectAtIndex:i]objectAtIndex:0]objectForKey:@"textoClase"];
            [view addSubview:lbl];

            [self.collectionView addSubview:view];
        }


        reusableview = headerView;
    }

            return reusableview;
    }
.

Номер столбца должен быть похож на количество ClasseSarr.

Это было полезно?

Решение

Я исправил мою проблему.Спасибо.

 RePrecioHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CollectionHeaderView" forIndexPath:indexPath];

        UILabel *lblHeader=(UILabel *)[headerView viewWithTag:MY_HEADER_LABEL_TAG];
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(5,0, 80, 30)];
        view.backgroundColor = [UIColor grayColor];

        lblHeader = [[UILabel alloc] initWithFrame:CGRectMake(2,3, 60, 10)];
        lblHeader.backgroundColor = [UIColor clearColor];
        lblHeader.textColor=[UIColor whiteColor];
        lblHeader.font = [UIFont systemFontOfSize:11.0f];
        lblHeader.numberOfLines=2;

        lblHeader.textAlignment=NSTextAlignmentCenter;
        lblHeader.text =[[[self.ClassesArr objectAtIndex:indexPath.section]objectAtIndex:0]objectForKey:@"textoClase"];
        [view addSubview:lblHeader];
        [headerView addSubview:view];
.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top