search

Home  >  Q&A  >  body text

IOS swift UICollectionView中cell的间距如何设置,请大神讲解。

最好能有个demo,感激不尽~

PHP中文网PHP中文网2772 days ago804

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:30:50

    You can use autolayerout to set it in the storyboard. This is my general approach because it is simple and fast. Alternatively, you can use this protocol UICollectionViewDelegateFlowLayout

    Rewrite a function of the collectionview below

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
            return sectionInsets
        }
    

    Then define the following variable outside the function, which is the same as the value returned above.

     private let sectionInsets = UIEdgeInsets(top: -5.0, left: 5.0, bottom: 0.0, right: 5.0)
    

    For the rest, you can refer to this http://www.cnblogs.com/ios8/p...

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:30:50

    Do you know how to set up OC? The interfaces are similar

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:30:50

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
            return sectionInsets
        }

    Override this method, which is used to specify the interval, the upper, lower, left, and right intervals.

    Welcome to follow Brother Biao’s technical blog: http://www.huangyibiao.com/

    reply
    0
  • Cancelreply