Ios 集合视图多个水平节标题

Ios 集合视图多个水平节标题,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我正在尝试创建一个具有水平标题部分的CollectionView标题,但问题是所创建的部分是垂直的,我希望所有内容都是动态的 为此,我使用了视图作为类似的补充元素:- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPat

我正在尝试创建一个具有水平标题部分的
CollectionView
标题,但问题是所创建的部分是垂直的,我希望所有内容都是动态的

为此,我使用了
视图作为类似的补充元素
:-

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionHeader) {

        DepartmentCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

        //UILabel *label = [[UILabel alloc] init];
        //label.tag = indexPath.row;
        headerView.officeName.text=[NSString stringWithFormat:@"%@",_officelist[indexPath.row]];
        [self.roadmapCollectionView addSubview:headerView.officeName];
        reusableview = headerView;
    }

    return reusableview;

}

请尝试以下代码(使用DateFlowLayout)

bool isPortrait=ui接口方向运动方向(方向)

这工作正常(这里我们根据图在
集合视图标题中创建标签和按钮):-

-(UICollectionReusableView*)collectionView:(UICollectionView*)collectionView用于种类的SupplementElementOfKind:(NSString*)种类索引路径:(NSIndexPath*)索引路径
{
UICollectionReusableView*reusableView=[collectionView出列ReusableSupplementaryViewofKind:UICollectionElementKindSectionHeader with ReuseIdentifier:@“HeaderView”forIndexPath:indexPath];
CGFloat x=0,y=0;

对于(int i=0;我是否使用自定义布局?我使用的是flow layout您可以添加标题内带有水平滚动条的collectionview(即UICollectionReusableView)
self.collectionView.frame = isPortrait ? CGRectMake(0, 0, 768, 180) : CGRectMake(0, 60, 246, 595);
self.collectionView.collectionViewLayout = isPortrait ? DateFlowLayout.new : UICollectionViewFlowLayout.new;
self.flowLayout = ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout);

self.flowLayout.scrollDirection = isPortrait ? UICollectionViewScrollDirectionHorizontal : UICollectionViewScrollDirectionVertical;
self.flowLayout.headerReferenceSize = isPortrait ? CGSizeMake(5, 30) : CGSizeMake(246, 40); //width is margin to the left of the header - must be bigger than 0 to show headers correct.
self.flowLayout.minimumInteritemSpacing = isPortrait ? 10 : 0;
self.flowLayout.minimumLineSpacing = isPortrait ? 17 : 7;
self.flowLayout.sectionInset = isPortrait ? UIEdgeInsetsMake(27, 30, 25, 0) : UIEdgeInsetsMake(0, 14, 0, 0);
//self.flowLayout.itemSize = CGSizeMake(58, 85); //You might need this
self.collectionView.alwaysBounceVertical = isPortrait ? NO : YES;
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

    CGFloat x=0,y=0;

    for (int i = 0;i<[_officelist count];i++)
    {
        id val=[officeSize objectAtIndex:i];
        CGFloat val1=[val floatValue];
            UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 10,val1-1,35)];

            newLabel.text=[NSString stringWithFormat:@"%@",_officelist[i]];

            newLabel.textAlignment = NSTextAlignmentCenter;

            newLabel.backgroundColor = [UIColor greenColor];
            [self.roadmapCollectionView addSubview:newLabel];

        x=x+val1+1;
    }
    for (int i=0; i<_departmentlist.count; i++) {

        dept=[_departmentlist objectAtIndex:i];
        id val=[officeSize objectAtIndex:i];
        CGFloat val1=[val floatValue];

        float val2=val1/[dept count];
            //NSLog(@"DEPT SIZE - %f",val2);

            for (int j = 0; j < [dept count]; j++)
            {
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(y, 50,val2-1, 25);
                [button setBackgroundColor:[UIColor yellowColor]];
                [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
                [button setTitle:[NSString stringWithFormat:@"%@",dept[j]] forState:UIControlStateNormal];

                [self.roadmapCollectionView addSubview:button];

                [deptSize addObject:[NSNumber numberWithFloat:y]];

                y=y+val2+1;

            }
}

    return reusableView;
}