Change WKInterfaceButton background image on tap

2.1k views Asked by At

I'm trying to change the background image of a WKInterfaceButton in my storyboard when a tap occurs. Also, on calling the setBackgroundImage to change the image, appendValue(1) does not work.

class keyPadInterfaceController : WKInterfaceController{
    @IBOutlet weak var OneClicked: WKInterfaceButton!
        let whiteImage = UIImage(named:"keybutton1.png")
        let goldImage = UIImage(named:"keybutton2.png")

    @IBAction func OneTapped(sender:AnyObject) {
        OneClicked.setBackgroundImage(goldImage)
        appendValue(1) 
    }
}
1

There are 1 answers

1
Daniel Storm On BEST ANSWER

To access images using setBackgroundImage you must pass them from the users iPhone first.

Alternatively, you can use setBackgroundImageNamed. As a result, WatchKit checks your WatchKit app bundle first, followed by the device-side cache.

OneClicked.setBackgroundImageNamed("keybutton2.png")