문제

각 열에 서로 다른 데이터가있는 콜렉션보기를 만들었습니다.그러나 그들을 별도로 만들기 위해서는 헤더를 추가해야합니다.하나의 헤더 만 추가 할 수 있습니다.이 코드는 다음과 같습니다.

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

열 번호는 classesars의 수와 같아야합니다 ..

도움이 되었습니까?

해결책

나는 내 문제를 해결했습니다.고마워.

 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