Home > Blockchain >  "Button" text appears on the UIButton when pressed
"Button" text appears on the UIButton when pressed

Time:09-04

I am using two buttons inside a TableViewCell. I am using system images for both of them. I have removed the Title from both of them as I don't want any text, only image. But when I click them, the text 'Button' which is the default title, appears again.

How to do I solve this?

import UIKit

class scheduleCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        editBtn.titleLabel?.text = ""
        deleteSchedule.titleLabel?.text = ""
    }

    @IBOutlet weak var timeLabel1: UILabel!
    
    @IBAction func edit(_ sender: Any) {
        
        
        print("EDIT BTN ")
        
    }
    @IBOutlet weak var timeLabel2: UILabel!
    
    @IBOutlet weak var editBtn: UIButton!
    
    @IBOutlet weak var deleteSchedule: UIButton!
    
    @IBAction func deleteBtn(_ sender: Any) {
        
        print("DELETE BTN ")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        timeLabel1.text = ""
        timeLabel2.text = ""
       
    }
    
}

CodePudding user response:

It's not a good idea to change a UIButton text by modifying the underlaying label text property directly, you should use the setTitle(_:for:) method like this:

editBtn.setTitle("", for: .normal)
  • Related