gpt4 book ai didi

ios - 在 tableView Cell 中看不到按钮的图像

转载 作者:行者123 更新时间:2023-11-28 06:11:06 25 4
gpt4 key购买 nike

我的 tableView 中有一个 UIButton,我试图更改它的图像,但是当我运行应用程序时 - 在模拟器和 iPhone 中,它显示什么都没有。

我的图片格式是PNG

这是我在 cellForRowAt 中的代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! notesTableViewCell
cell.buttonImage.setImage(UIImage(named: "imagetest2.png"), for: UIControlState.normal)
cell.buttonImage.imageView?.contentMode = .scaleAspectFit
cell.buttonImage.tag = indexPath.row
cell.buttonImage.addTarget(self, action: #selector(buttonImageFunc), for: .touchUpInside)
cell.selectionStyle = UITableViewCellSelectionStyle.none

return cell
}

这是 notesTableViewCell 代码:

class notesTableViewCell: UITableViewCell {

@IBOutlet var buttonImage: UIButton!

override func awakeFromNib() {
super.awakeFromNib()
}

最佳答案

Note: Go to Assets.xcassets in your project. then create New Image Set with name imagetest. after that drag and drop imagetest2.png into sample image set

please check button type: .custom

cell.buttonImage.setImage(UIImage(named: "imagetest"), for: .normal)

关于ios - 在 tableView Cell 中看不到按钮的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46571282/

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