点按即可更改WKInterfaceButton背景图片

时间:2015-05-19 23:03:08

标签: ios swift apple-watch wkinterfacebutton

我正在尝试在点击发生时更改故事板中WKInterfaceButton的背景图片。此外,在调用setBackgroundImage更改图片时,appendValue(1)无效。

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 个答案:

答案 0 :(得分:1)

使用setBackgroundImage you must pass them from the users iPhone first访问图片。

或者,您可以使用setBackgroundImageNamed。因此,WatchKit checks your WatchKit app bundle first, followed by the device-side cache

OneClicked.setBackgroundImageNamed("keybutton2.png")