删除收藏夹视图的顶部栏

时间:2019-03-22 03:51:22

标签: uicollectionview uinavigationbar cell space uicollectionviewlayout

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

enter image description here

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)
    }
}

0 个答案:

没有答案