My first Apple Watch mini-game-guess number (Swift)

Source: Internet
Author: User

This is a small app implemented on AppleWatch, developed in the language of Swift. is a guessing number of the game, the screen will appear different numbers of scrolling, and can control the beginning of the game to end, let others guess the numbers. Isn't it interesting. can also more people to play this game, than everyone who last number big. I have uploaded the app to Https://

Since this application is mostly implemented on watch, there is no effect on the phone and there is only a white interface. The implementation steps are as follows:

(1) Create a new Apple Watch app in iOS,

(2) Then import 3 pictures, respectively, to mark the three-in-one. The design in Interface.storyboard is as follows:

(3) The following are implemented in Interfacecontroller.swift:

Import Watchkitimport foundationclass Interfacecontroller:wkinterfacecontroller {@IBOutlet var image:wkinterfaceimag  E!    @IBOutlet var button:wkinterfacebutton!    Timer; var timer:nstimer! Determine whether to start or end the Carousel; var Isstart:bool = true//picture subscript; var index:int = 1 override func Awakewithcontext (context:anyobje CT?)  {Super.awakewithcontext (context)//Configure interface objects here.    } override func Willactivate () {//This method was called when watch View Controller was about-to was visible to user  Super.willactivate ()} override func Diddeactivate () {//This method was called when watch View Controller is no Longer visible super.diddeactivate ()} @IBAction func buttonclicked () {if (Isstart) {//start scrolling picture a Ddtimer () button.settitle ("End")}else{//stop scrolling picture self.timer.invalidate () Self.timer = nil Butto N.settitle ("Start")} Isstart =!isstart} func addtimer () {//Picture-carousel timer; self.tiMer = Nstimer.scheduledtimerwithtimeinterval (0.1, target:self, selector: "NextImage:", Userinfo:nil, Repeats:true)} Func NextImage (sender:anyobject!) {Let str = "img" + String (Index) image.setimagenamed (str) index++ if (index = = 4) {Inde x = 1}}

(4) The following results are achieved:

GitHub home: Welcome everyone to visit!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My first Apple Watch mini-game-guess number (Swift)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.