Declare the attributes in. h as follows
@property (Retain, nonatomic) UIWindow *window;
@property (nonatomic, retain) UIView *aview;
@property (nonatomic, retain) UIButton *button;
The following are implemented in. m
@implementation Mayappdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{
{Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
Override point for customization after application launch.
_aview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 320, 568)];
_aview.backgroundcolor = [Uicolor Lightgraycolor];
[Self.window Addsubview:_aview];
[_aview release];
for (int i = 0; i < 5; i++) {
for (int j = 0; J < 5; J + +) {
_button = [[UIButton alloc] Initwithframe:cgrectmake (+ 50 * j, + 50)];
_button.adjustsimagewhenhighlighted = NO;
[_button setbackgroundimage:[uiimage imagenamed:@ "8.png"] forstate:uicontrolstatenormal];
[_button setbackgroundimage:[uiimage imagenamed:@ "2.png"] forstate:uicontrolstateselected];
[_button addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];
_button.tag = + + * i + j;
[_aview Addsubview:_button];
[_button release];
}
}
Self.window.backgroundColor = [Uicolor Whitecolor];
[Self.window makekeyandvisible];
return YES;
}
-(void) Click: (UIButton *) btn
{
btn.selected =!btn.selected;
UIButton *upbutton = (UIButton *) [_aview viewwithtag:btn.tag-10];
upbutton.selected =!upbutton.selected;
UIButton *downbutton = (UIButton *) [_aview ViewWithTag:btn.tag + 10];
downbutton.selected =!downbutton.selected;
UIButton *leftbutton = (UIButton *) [_aview viewwithtag:btn.tag-1];
leftbutton.selected =!leftbutton.selected;
UIButton *rightbutton = (UIButton *) [_aview ViewWithTag:btn.tag + 1];
rightbutton.selected =!rightbutton.selected;
}
Lights off Game (IOS)