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: