美文网首页技术分享
viewForSupplementaryElementOfKin

viewForSupplementaryElementOfKin

作者: 驰宝 | 来源:发表于2017-08-14 15:16 被阅读40次

    为了降低代码耦合性,通常自定义UICollectionViewFlowLayout。今天在自定义UICollectionViewFlowLayout时,想设置UICollectionView的footerView,但viewForSupplementaryElementOfKind不执行,改成系统的UICollectionViewFlowLayout就可以。


    自定义UICollectionViewFlowLayout添加header 和footer的解决方法:

    - (nullableNSArray<__kindofUICollectionViewLayoutAttributes*> *)layoutAttributesForElementsInRect:(CGRect)rect{

    NSMutableArray*attributes = [[superlayoutAttributesForElementsInRect:rect]mutableCopy];

    for(NSIntegeri =0; i <_numberOfCells; i++) {

    NSIndexPath*indexPath = [NSIndexPathindexPathForItem:iinSection:0];

    UICollectionViewLayoutAttributes*attribute = [selflayoutAttributesForItemAtIndexPath:indexPath];

    [attributesaddObject:attribute];

    }

    for(UICollectionViewLayoutAttributes*attrsinattributes) {

    if([attrsrepresentedElementKind] ==UICollectionElementKindSectionFooter) {

    CGRectheaderRect = [attrsframe];

    headerRect.size.height=100;

    headerRect.size.width=SCREEN_SIZE.width;

    [attrssetFrame:headerRect];

    break;

    }

    }

    returnattributes;

    }

    相关文章

      网友评论

        本文标题:viewForSupplementaryElementOfKin

        本文链接:https://www.haomeiwen.com/subject/fvyurxtx.html