从UICollectionView

时间:2015-04-27 16:50:12

标签: ios swift ios8 uicollectionview

小猪退出这个SO question

如果我改变

 cell.layer.borderWidth = 0.0

它会删除单元格顶部和底部的边框,但不会删除左右边框。 http://imgur.com/c2oDzjc无论如何都要删除所有边框和单元格间距,以便图像完全齐平?我的代码:

var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

}

func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! CollViewCell
    //cell.imageCell.image = UIImage(named: self.gridIMages[indexPath.row])

    cell.backgroundColor = UIColor.whiteColor()
    cell.layer.borderColor = UIColor.blackColor().CGColor
    cell.layer.borderWidth = 0.0
    cell.frame.size.width = screenWidth / 3
    cell.frame.size.height = screenHeight / 3

    return cell
}

1 个答案:

答案 0 :(得分:2)

您无法在任何地方分配布局。你只是创造它并且不使用它。

因此collectionView.collectionViewLayout = layout中需要viewDidLoad。但是在界面构建器中设置它可能更容易。