Today let's create one of the simplest Apple Watch programs and implement the simplest response. The Xcode version is 7. Implemented as follows:
(1) To create a watchOS application:
。
(2) Note that the following "include Glance Scene" should be selected. As shown in figure:
。
(3) As with iOS development, we can also drag controls directly, and in interface controller drag the controls as follows:
。
(4) through the Segue line, the implementation of the code in the Interfacecontroller.swift is as follows:
Import watchkit
Import Foundation
class Interfacecontroller:wkinterfacecontroller {
@IBOutlet var mylabel:wkinterfacelabel!
Override func Awakewithcontext (Context:anyobject?) {
Super.awakewithcontext (context)
//Configure interface objects here.
}
Override Func Willactivate () {
//This method was called when watch View Controller are about to are visible to user
Super.willactivate ()
}
override Func Diddeactivate () {
//This method was called when watch View Controller is no longer visible
super.diddeactivate ()
}
@IBAction func btnclicked () {
Mylabel.settext (" 111111 ")
}
}
(5) The running program is as follows: by clicking the button, you can change the text in the label below;
。
。
(6) Of course, we can also design the interface in the glance, by clicking on the control in the glance, you can click into the app;
.
GitHub home: https://github.com/chenyufeng1991. You are welcome to visit.