美文网首页
UICollectionView 的记录

UICollectionView 的记录

作者: de_fly | 来源:发表于2016-07-14 14:52 被阅读47次

    创建

    letlayout =UICollectionViewFlowLayout()

    layout.minimumLineSpacing=8

    layout.minimumInteritemSpacing=8

    //layout.sectionInset = UIEdgeInsetsMake(8, 0, 0, 8)

    //layout.itemSize = CGSizeMake(self.view.bounds.size.width - 0,172)

    collectionView = HJMPullToRefreshCollectionView(frame:self.view.bounds, collectionViewLayout: layout)

    collectionView.backgroundColor =UIColor(hexString:"#f0f0f0")

    self.view.addSubview(collectionView)

    collectionView.delegate =self

    collectionView.dataSource =self

    collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: cellIdentify)

     总是记不住的 UICollectionViewDelegateFlowLayout

    extensionStydyStatusViewController:UICollectionViewDelegateFlowLayout{

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, sizeForItemAtIndexPath indexPath:NSIndexPath) ->CGSize

    @available(iOS6.0, *)

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, insetForSectionAtIndex section:Int) ->UIEdgeInsets

    @available(iOS6.0, *)

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section:Int) ->CGFloat

    @available(iOS6.0, *)

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section:Int) ->CGFloat

    @available(iOS6.0, *)

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, referenceSizeForHeaderInSection section:Int) ->CGSize

    @available(iOS6.0, *)

    optionalpublicfunccollectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, referenceSizeForFooterInSection section:Int) ->CGSize

    }

    UICollectionElementKindSectionHeader

    UICollectionElementKindSectionFooter

    // 自动布局的时候使用

    layout.estimatedItemSize =CGSizeMake(self.view.bounds.size.width -0,172)

    在Cell 中

    //forces the system to do one layout pass

    varisHeightCalculated:Bool=false

    overridepublicfuncpreferredLayoutAttributesFittingAttributes(layoutAttributes:UICollectionViewLayoutAttributes) ->UICollectionViewLayoutAttributes{

    //Exhibit A - We need to cache our calculation to prevent a crash.

    if!isHeightCalculated{

    setNeedsLayout()

    layoutIfNeeded()

    letsize =contentView.systemLayoutSizeFittingSize(layoutAttributes.size)

    varnewFrame = layoutAttributes.frame

    newFrame.size.width=CGFloat(ceilf(Float(size.width)))

    newFrame.size.height=CGFloat(ceilf(Float(size.height)))

    layoutAttributes.frame= newFrame

    layoutAttributes.hidden=false

    //isHeightCalculated = true

    }

    returnlayoutAttributes

    }

    使用自动布局是可能会有性能问题

    UITableView ios8 以上

    tableView.separatorStyle = .None

    tableView.rowHeight =UITableViewAutomaticDimension

    tableView.estimatedRowHeight =180

    相关文章

      网友评论

          本文标题:UICollectionView 的记录

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