[英]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.