I have a button that displays an image from my Assets, on click of a button I want to replace the image by text,
I am doing this,
workExpExpand.setImage(nil, forState: .Normal)
workExpExpand.setTitle("Done", forState: .Normal)
the image disappears, but the text is blank.
What can I do?
Your code is correct. So I suspect you are having the same issue mentioned here. For fixing it you need to set the title color of that button, by default the title color is white and that's why you are not seeing the text:
workExpExpand.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
Your code is right. But you have specify the title color as default color is white due to which you are not able to see text.
@IBAction func btnTapped(sender: AnyObject) {
btn.setImage(nil, forState: .Normal)
btn.setTitle("Done", forState: .Normal)
btn.setTitleColor(UIColor.redColor(), forState: .Normal)
}
For swift 5 to remove image from button and set title
self.btnRecord.setImage(nil, for: .normal)
self.btnRecord.setTitle("REC", for: .normal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With