[英]Can't see image of button in tableView Cell
我的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()
}
注意:转到项目中的
Assets.xcassets
。 然后创建名为imagetest
新图像集。 然后将imagetest2.png
拖放到示例图像集中
请检查按钮类型:.custom
cell.buttonImage.setImage(UIImage(named: "imagetest"), for: .normal)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.