类似excel跨行跨列的表格

1.例子1

http://www.code4app.com/thread-15049-1-1.html

Tag:

项目介绍:



上次没有传demo 附件的github 地址贴出来。这次贴出来https://github.com/conquerLust/FromLikeExcel
类似excel跨行跨列的表格
采用UICollectionView实现,关键是自定义UICollectionViewLayoutAttributes 自定义了cell的大小来实现跨行跨列表格
   关键代码如下:
for (int section = 0; section < [self.collectionView numberOfSections]; section ++) {
        NSMutableArray *sectionAttributes = [@[] mutableCopy];
        for (NSUInteger row = 0; row < _allColumns; row++) {
            CGSize itemSize = [self.itemsSize[section][row] CGSizeValue];
            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:row inSection:section];
            UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
            attributes.frame = CGRectIntegral(CGRectMake(xOffset, yOffset, itemSize.width, itemSize.height));
            if (section == 0 && row < _lockColumn) {
                attributes.zIndex = 2015;
            } else if (section == 0 || row < _lockColumn) {
                attributes.zIndex = 2014;
            }
            if (section == 0) {
                CGRect frame = attributes.frame;
                frame.origin.y = self.collectionView.contentOffset.y;
                attributes.frame = frame;
            }

            if (row < _lockColumn) {
                CGRect frame = attributes.frame;
                float offsetX = 0;
                if (index > 0) {
                    for (int i = 0; i < row; i++) {
                        offsetX += MinmumItemWidth;
                    }
                }

                frame.origin.x = self.collectionView.contentOffset.x + offsetX;
                attributes.frame = frame;
            }

            [sectionAttributes addObject:attributes];

            xOffset = xOffset + MinmumItemWidth;
            column ++;

            if (column == _allColumns) {
                if (xOffset > contentWidth) {
                    contentWidth = xOffset;
                }

                // 重置基本变量
                column = 0;
                xOffset = 0;
                yOffset += MinmumItemHeight;
            }
        }
        [self.itemAttributes addObject:sectionAttributes];
    }

    // 获取右下角最有一个item,确定collectionView的contentSize大小
    UICollectionViewLayoutAttributes *attributes = [[self.itemAttributes lastObject] lastObject];
    contentHeight = attributes.frame.origin.y + attributes.frame.size.height;
    _contentSize = CGSizeMake(contentWidth, contentHeight);
 

例二

excelTable 表格实现
Tag:

项目介绍:

描述不如看图 

http://github.com/ongfei/excelTable
有用 请git上给颗星

 

posted @ 2018-12-13 18:05  sundaysios  阅读(364)  评论(0)    收藏  举报