uicollectionview - 删除集合视图的顶部栏
问题描述
我有一个小的表情符号集合视图,当用户点击表情符号按钮时会显示该视图。我想摆脱顶部栏空间,以便背景,例如,全是蓝色的。我尝试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)
}
}
解决方案
推荐阅读
- c# - 操纵杆不旋转超出范围
- sql - 有没有办法为 SQL 中的特定 ID 生成下一个字母“序列码”?
- reactjs - 如何在 React 中传递这样的 URL 参数?
- ios - 如何获得我之前分配的标记位置?ios迅捷
- node.js - 在 Lambda 节点 for 循环中使用 Promise
- node.js - 在具有相同 ID 的 elasticsearch 2 文档中
- python-3.x - 如何在熊猫中找到完整的空行
- sql - 连续选择编号较低的记录
- python - 将 grep 结果返回给变量,在 python 中执行吗?
- c# - 在 EF Core 3.1 中替换 HasColumnAnnotation() 的最佳方法是什么