IOS off Light Game

Source: Internet
Author: User

One

Create a root View Controller for window first

In the AppDelegate.h file

-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions

// Create a root view Controller    for window Rootviewcontroller *rootviewcontroller = [[Rootviewcontroller alloc]init];     = Rootviewcontroller;

In the rootviewcontroller.m file

-(void) viewdidload

{

int count = 0; define The Count count to be the tag tag stored value

UIImage *one = [UIImage imagenamed:@ "H.png"]; // set up a picture

for (int i=0; i<7; i++) {

for (int j=0; j<5; j + +) {

count++;

UIButton *button = [UIButtonbuttonwithtype:uibuttontype Custom];

button. frame = cgrectmake(*j, +i* );

button. tag = count;

[Button setimage: one forstate:uicontrolstatenormal];

[Button addTarget:self action:@selector(touch:) forcontrolevents:uicontroleventtouchupinside];

[Self. View addsubview: button];

}

count+= 5 ; control the tag tag to implement the tag tag of the next line

}

[Superviewdidload];

Do any additional setup after loading the view.

}

-(void) Touch: (ID) Sender

{

UIButton *button = (UIButton*) sender;

for (int i=0; i<=; i++) {

UIButton *current = (UIButton*) [self. View Viewwithtag: i]; // Set the current button's Click event

// below is the control tag around, up and down

if (I==button. Tag-1) | | (I==button. tag+1) | | (I==button. tag-| | (I==button. tag+)) {

if (Current. currentimage ==[UIImage imagenamed:@ "H.png"]) {

[ Current setimage: [UIImageimagenamed:@ "g.png"] forstate:uicontrolstatenormal];

}

Else

{

[ Current setimage: [UIImageimagenamed:@ "h.png"] forSt Ate:uicontrolstatenormal];

}

}

}

}

The final result is this:

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: info-contact@alibabacloud.com 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.