gpt4 book ai didi

ios - 如何在 swift 2.0 中正确对齐 Collection View 单元格

转载 作者:行者123 更新时间:2023-11-29 00:47:22 25 4
gpt4 key购买 nike

我在使用 UICollectionView 时遇到问题。我制作了一个 Collection View ,它完美地显示了单元格及其元素。但是,问题是应用程序打开时底部单元格被隐藏。之后,如果我滚动到顶部,则最后一行 Collection View 单元格将打开。如何纠正它们??请引用以下屏幕截图。非常感谢!

它显示如下图(截图一)..

Screenshot one

但我想在没有第一次滚动的情况下显示如下图所示的 Collection View 单元格(屏幕截图二)...

ScreenShot two

我的编码是:

//  ViewController.swift

import UIKit

class ViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate{

@IBOutlet var collectionView: UICollectionView!

var titles = ["Events","Visitor Space","Contact Us","Facebook","Videos","WebSite"]
var icons = [UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover")]

override func viewDidLoad() {
super.viewDidLoad()
}


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return titles.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! HomeCollectionCells
cell.homeLabel.text = titles[indexPath.row]
cell.homeImage.image = icons[indexPath.row]
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}

最佳答案

尝试在 viewDidLoad 中添加这个

self.automaticallyAdjustsScrollViewInsets = false

关于ios - 如何在 swift 2.0 中正确对齐 Collection View 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com