微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法在 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 举报,一经查实,本站将立刻删除。