【问题标题】:Remove all cell space from UICollectionView从 UICollectionView 中删除所有单元格空间
【发布时间】:2015-04-27 16:50:11
【问题描述】:

小猪支持这个 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
}

【问题讨论】:

    标签: ios swift ios8 uicollectionview


    【解决方案1】:

    您没有在任何地方分配布局。你只是创建它而不使用它。

    所以你需要collectionView.collectionViewLayout = layout 中的viewDidLoad。但是在界面生成器中设置它可能更容易。

    【讨论】:

    • 感谢您的关注!因此,添加该行删除了第一列边框。但第二个仍然存在。 imgur.com/ISEyl3i
    • 尝试打印出每个单元格的单元格宽度。宽度可能是 320,所有单元格都是 106。然后你会丢失两个像素(尽管我只是在疯狂猜测)。也总是使用 collectionView.frame.width,而不是 ScreenWidth。在您的情况下,它将是相同的,但如果您决定稍后调整 collectionView 的大小,您的代码将无法正常工作,这将。
    猜你喜欢
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多