无法在 iOS Swift 中使用 CollectionView 制作动态标签

问题描述

我正在使用 collectionioview 创建如下动态标签

enter image description here

为此,我采用了 collectionview 内部视图,而在 collectionview 中,我采用了 textfield

enter image description here

但是有了这个我可以创建静态标签..但是我需要动态标签..如果我写一些标签它应该显示在视图上..怎么做

静态标签代码

 class ViewController: UIViewController{
     var langArra = [String]()

@IBOutlet weak var collectionView: UICollectionView!

override func viewDidLoad() {
super.viewDidLoad()
let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        self.collectionView.collectionViewLayout = layout
        self.collectionView!.contentInset = UIEdgeInsets(top: -10,left: 10,bottom:0,right: 30)

        if let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
            layout.minimumInteritemSpacing = 10
            layout.minimumLinespacing = 10
            layout.itemSize = CGSize(width: 100,height: 30)
            layout.invalidateLayout()
        }

    }

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


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

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell",for: indexPath as IndexPath) as! LangCollectionViewCell

    cell.langTf.delegate = self
    
    langArra.append(cell.langTf.text!)

   cell.langTf.text = langArra[indexPath.row]

    collectionView.reloadData()
return cell
}

如何使用 collectionview 制作静态标签,或者是否有任何用于 swift 静态标签的库.. 请帮忙。

虽然上面的代码运行 0/p 如下:这里如何在文本字段中编写文本..当我运行文本字段时不显示..这里如何编写文本..请在这里建议我

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)