swift3 - Trying to update the background image of a UIButton on click -


i have button set background image. it's png of image being transparent. when image tapped on (selected), update background image of button different image. seems working, it's not removing original background image. seems placing new background image behind old one. transparent background image seems above selected background image.

setting background image:

owedtotalbtn.setbackgroundimage( uiimage.init(named:"total-owed"), for: .normal) 

updating background image 1 button tapped:

@ibaction func showowed(_ sender: any) {   owedtotalbtn.setbackgroundimage( uiimage.init(named:"total-owed-selected"), for: .normal)  } 

you have set background image both normmal state. try code:

owedtotalbtn.setbackgroundimage( uiimage.init(named:"total-owed"), for: .normal) owedtotalbtn.setbackgroundimage( uiimage.init(named:"total-owed"), for: .selected)  @ibaction func showowed(_ sender: any) {   sender.isselected = !sender.isselected  } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -