我在我的tableView
中有一個UIButton
,我試圖改變它的圖像,但是當我運行該應用程序時 - 在模擬器和iPhone中,它什麼也沒有顯示。在tableview中看不到按鈕的圖像單元格
我的圖片格式是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()
}
你真的看到表視圖按鈕,如果你設定一個固定的背景顏色呢? – arvidurs
@arvidurs是的,當我設置backgroundColor和當我只是把文本。 – Eliko
png的大小是多少?嘗試設置2x 3x分辨率,默認大小爲32像素×32像素 – arvidurs