As you are saying that you can’t nil the button’s text, you should do this,
You can implement this Bool extension also,
extension Bool {
mutating func toggle() {
self = !self
}
}
@IBAction func myButton(_ sender: UIButton) {
sender.titleLabel?.isHidden.toggle()
}
this will show and hide your Button’s titleLabel
text.
UPDATE
@IBAction func btnTapped(_ sender: UIButton) {
sender.isSelected.toggle()
if sender.isSelected == true {
sender.setTitleColor(UIColor.clear, for: .normal)
} else {
sender.setTitleColor(UIColor.blue, for: .normal)
}
}
4
solved How to hide show UIButton text not button in IOS Swift [closed]