首页 > 解决方案 > 删除集合视图的顶部栏

问题描述

我有一个小的表情符号集合视图,当用户点击表情符号按钮时会显示该视图。我想摆脱顶部栏空间,以便背景,例如,全是蓝色的。我尝试top bar在 storyboard 上制作None.。我怎样才能删除这个空间?

在此处输入图像描述

import UIKit

class EmojiViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    let emojiImages = [...the pics...]

    var selectedIndex: Int?
    var estimateWidth = 100.0
    var cellMarginSize = 10.0

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

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

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

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "emojiCell", for: indexPath) as! EmojiViewCell
        let emoji = emojiImages[indexPath.row]
        cell.emojiImage.image = UIImage(named: emojiImages[indexPath.row])

        if selectedIndex == indexPath.row {
            cell.backgroundColor =  UIColor.red
            self.dismiss(animated: true, completion: nil)
            UserDefaults.standard.set(emoji, forKey: "emojiPicked")
        }else{
            cell.backgroundColor = UIColor.clear
        }
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        selectedIndex = selectedIndex == indexPath.row ? nil : indexPath.row
        collectionView.reloadData()
    }
}

extension EmojiViewController: UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 40, height: 40)
    }
}

标签: uicollectionviewuinavigationbarcellspaceuicollectionviewlayout

解决方案


推荐阅读