gpt4 book ai didi

ios - 如何在 uicollectionview 中设置我的 UIButton 标题

转载 作者:行者123 更新时间:2023-11-29 05:51:57 25 4
gpt4 key购买 nike

所以我想用我的数组设置这样的按钮标题,但结果按钮标题没有显示我的数组

// View Controller

let menus = ["Topokki","Sundubu","Galbitang"]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

}

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

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell



cell.menusButton.titleLabel?.text = menus[indexPath.item]

return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.item)
}

//collectionviewcell类

class CollectionViewCell: UICollectionViewCell {

@IBOutlet weak var menusButton: UIButton!


}

最佳答案

尝试:

cell.menusButton.setTitle(menus[indexPath.item], forState: .normal)

关于ios - 如何在 uicollectionview 中设置我的 UIButton 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55580482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com