CollectionView单元格很小

发布于 2025-02-04 07:01:55 字数 1527 浏览 2 评论 0原文

我在项目中的CollectionView中,我在CollectionViewCell中添加了一些按钮和标签,并进行了所有自动划分,但是每当我运行项目时,CollectionViewCell都比计划的要小,或者在我的Xcode Storyboard上显示的解决方案,是否有其他解决方案?

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "mainCell", for: indexPath as IndexPath) as! MainCollectionViewCell
        cell.config(data: array1[indexPath.row])
        return cell
    }

class MainCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var profileImage: UIImageView!
    @IBOutlet weak var postAuthor: UILabel!
    @IBOutlet weak var postChannel: UILabel!
    @IBOutlet weak var postDate: UILabel!
    @IBOutlet weak var votesNumber: UILabel!
    
    
    func config(data:PostModel){
        self.profileImage.image = data.authorPhoto
        self.postAuthor.text = data.authorName
        self.postChannel.text = data.channelPosted
        self.postDate.text = data.date
        self.votesNumber.text = String(data.votesCount)
    }
    
}

屏幕截图更好地理解

“故事板”

”我运行项目之后”

I've CollectionView in my project, I added some buttons and labels inside CollectionViewCell and did all the auto-layout, but anytime I run my project the CollectionViewCell is smaller than it is planned or appeared on my xcode storyboard, any solutions ?

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "mainCell", for: indexPath as IndexPath) as! MainCollectionViewCell
        cell.config(data: array1[indexPath.row])
        return cell
    }

class MainCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var profileImage: UIImageView!
    @IBOutlet weak var postAuthor: UILabel!
    @IBOutlet weak var postChannel: UILabel!
    @IBOutlet weak var postDate: UILabel!
    @IBOutlet weak var votesNumber: UILabel!
    
    
    func config(data:PostModel){
        self.profileImage.image = data.authorPhoto
        self.postAuthor.text = data.authorName
        self.postChannel.text = data.channelPosted
        self.postDate.text = data.date
        self.votesNumber.text = String(data.votesCount)
    }
    
}

screenshots for better understanding

storyboard

after I run the project

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文