Uiimage * IMA = [uiimage imagenamed: @ "1.png"]; for (INT I = 0; I <5; I ++) {for (Int J = 0; j <5; j ++) {buttonsubview * button = [buttonsubview buttonwithtype: uibuttontypesystem]; button. frame = cgrectmake (5 + 63 * j, 100 + 63 * I, 58, 58); [Button setbackgroundimage: IMA forstate: uicontrolstatenormal]; [Button addtarget: Self action: @ selector (Click :) forcontrolevents: uicontroleventtouchupinside]; button. tag = 100 + I * 10 + J; button. flag = yes; // 0 [self. view addsubview: button] ;}} buttonsubview * BTN = [buttonsubview buttonwithtype: uibuttontypesystem]; BTN. frame = cgrectmake (100,450,120, 40); [BTN settitle: @ "" forstate: uicontrolstatenormal]; [BTN addtarget: Self action: @ selector (touch :) forcontrolevents: uicontroleventtouchupinside]; [self. view addsubview: BTN];}
Set background and start button
-(Void) Click :( buttonsubview *) BTN {uiimage * lamp = [uiimage imagenamed: @ "2.png"]; uiimage * IMA = [uiimage imagenamed: @" 1.png"]; nsinteger A [5] = {BTN. tag, BTN. tag + 1, BTN. tag-1, BTN. tag + 10, BTN. tag-10}; For (INT I = 0; I <5; I ++) {buttonsubview * button = (buttonsubview *) [self. view viewwithtag: A [I]; If (button. flag = Yes) {[Button setbackgroundimage: lamp forstate: uicontrolstatenormal]; button. flag = no;} else {[Button setbackgroundimage: IMA forstate: uicontrolstatenormal]; button. flag = Yes ;}}// set the random light-on (void) touch (buttonsubview *) bun {uiimage * lamp = [uiimage imagenamed: @ "2.png"]; uiimage * IMA = [uiimage imagenamed: @ "1.png"]; for (INT I = 100; I <145; I ++) {buttonsubview * button = (buttonsubview *) [self. view viewwithtag: I]; button. flag = arc4random () % 2; If (button. flag = 1) {[Button setbackgroundimage: lamp forstate: uicontrolstatenormal]; button. flag = 0;} else {[Button setbackgroundimage: IMA forstate: uicontrolstatenormal]; button. flag = 1 ;}}}
Set to control the brightness of the surrounding lights until all the lights are turned off.
Realization of light-off games