首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在uicollection视图中设置我的UIButton标题

如何在uicollection视图中设置我的UIButton标题
EN

Stack Overflow用户
提问于 2019-04-09 03:27:31
回答 1查看 79关注 0票数 0

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

//viewcontroller

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

//集合视图单元格类

class CollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var menusButton: UIButton!


}
EN

回答 1

Stack Overflow用户

发布于 2019-04-09 03:29:56

尝试:

cell.menusButton.setTitle(menus[indexPath.item], forState: .normal)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55580482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档