美文网首页
JMWaterFlow--快速布局瀑布流

JMWaterFlow--快速布局瀑布流

作者: Jimmy_P | 来源:发表于2015-12-14 21:14 被阅读173次

JMWaterFlow

JMWaterFlow 是本人 Jimmy 使用Swift语言对常见的 瀑布流 布局做的封装。 它使用UICollectionView来布局瀑布流,通过自定义layout布局来实现,简单易用。

Github地址:

https://github.com/JimmyPeng4iOS/JMWaterFlow


  • 可自定义布局参数:


    JMWaterFlow.png

使用方式

  • 构造方法
    let layout = WaterFlowViewLayout()
   //构造方法
   init()
   {
       super.init(collectionViewLayout: layout)
   } 
  • 初始化
        let Margin:CGFloat = 8;
        
        /// 瀑布流四周的间距
        layout.sectionInsert = UIEdgeInsets(top: Margin, left: Margin, bottom: Margin, right: Margin)
        
        /// 瀑布流列数
        layout.column = 5
        
        /// 列间距
        layout.columnMargin = Margin
        
        /// 行间距
        layout.rowMargin = Margin
        
        // 设置代理
        layout.delegate = self
  • 实现代理方法
//MARK: 代理方法
    /// 返回每个cell的高度,需要heightForWidth等比例缩放后的
    func waterFlowViewLayout(waterFlowViewLayout: WaterFlowViewLayout, heightForWidth: CGFloat, atIndexPath: NSIndexPath) -> CGFloat
    {
        return CGFloat(100 + arc4random_uniform(50))//测试使用随机值
    }

    ///返回cell的数量
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return 500//测试
    }
    
    //返回cell
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ReuseIdentifier, forIndexPath: indexPath)
        cell.backgroundColor = UIColor.randomColor()//测试使用随机色
        return cell
    }

最后 再来一遍github地址 (๑•̀ㅂ•́)و✧

https://github.com/JimmyPeng4iOS/JMWaterFlow


相关文章

  • JMWaterFlow--快速布局瀑布流

    JMWaterFlow JMWaterFlow 是本人 Jimmy 使用Swift语言对常见的 瀑布流 布局做的封...

  • 瀑布流布局 的学习

    1- 实现瀑布流布局效果 瀑布流效果瀑布流代码木桶布局效果木桶布局代码瀑布流布局 2- 实现一个新闻瀑布流新闻...

  • 瀑布流、木桶布局

    瀑布流 瀑布流效果代码 木桶布局 木桶布局效果(加载有点慢)代码

  • 瀑布流照片墙布局

    title: 瀑布流照片墙布局 瀑布流概念 瀑布流布局是错落式的布局方式。它有一个特点,整个布局以列为单位,下一个...

  • CSS经典布局

    圣杯布局 瀑布流

  • 瀑布流

    瀑布流布局瀑布流jsonp新闻页

  • 瀑布流布局_木桶布局

    题目1: 实现一个瀑布流布局效果 瀑布流 题目2:实现木桶布局效果 木桶布局 题目3:**实现一个新闻瀑布流新闻网...

  • 瀑布流和懒加载结合

    实现一个瀑布流布局效果 瀑布流

  • 瀑布流

    什么是瀑布流: 欣赏 pinterest 样式分析 瀑布流,又被称作为瀑布流式布局,是一种比较流行的网站页面布局方...

  • 瀑布流

    1、什么是瀑布流 瀑布流,又称瀑布流式布局。是比较流行的一种网站页面布局,视觉表现为参差不齐的多栏布局,随着页面滚...

网友评论

      本文标题:JMWaterFlow--快速布局瀑布流

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