0% found this document useful (0 votes)
37 views2 pages

Alert

The document defines code to display a UIAlertView with custom "Yes" and "No" buttons when the game is exited. It initializes a UIAlertView with the title and message. It then creates two custom UIButton subviews for the "Yes" and "No" options using stretched images for different states. Target actions are added to call a pressAlert method when tapped. The buttons are added as subviews and the alert is displayed.

Uploaded by

Vinay Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Alert

The document defines code to display a UIAlertView with custom "Yes" and "No" buttons when the game is exited. It initializes a UIAlertView with the title and message. It then creates two custom UIButton subviews for the "Yes" and "No" options using stretched images for different states. Target actions are added to call a pressAlert method when tapped. The buttons are added as subviews and the alert is displayed.

Uploaded by

Vinay Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*UIView *alertMessage=[[[UIView alloc]

initWithFrame:CGRectMake(10, 80, 300,250)] autorelease];

[self.view addSubview:alertMessage];*/

alert = [[[UIAlertView alloc] initWithTitle:@"Exit?" message:@"Do you


really want to Quit this game?" delegate:self cancelButtonTitle:nil otherButtonTitles:nil] autorelease];
//alert.frame=CGRectMake(10, 80, 300, 200);
//alert.backgroundColor=[UIColor whiteColor];
//alert.superview.backgroundColor=[UIColor whiteColor];
//[alert setAlpha:1];
/*UIImage *theImage = [UIImage imageNamed:@"screen2.png"];
//theImage = [theImage stretchableImageWithLeftCapWidth:16
topCapHeight:16];
CGSize theSize = [alert frame].size;

UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[[alert layer] setContents:[theImage CGImage]];*/

UIButton *btnYes=[[UIButton buttonWithType:UIButtonTypeCustom]


retain];
btnYes.tag=0;
btnYes.frame = CGRectMake(0.0, 110.0, 78.0, 37.0);
btnYes.backgroundColor = [UIColor clearColor];

UIImage *yesImage= [UIImage imageNamed:@"yes1.png"];


UIImage *btnYesImage = [yesImage
stretchableImageWithLeftCapWidth:78 topCapHeight:37];
[btnYes setBackgroundImage:btnYesImage
forState:UIControlStateNormal];

UIImage *yesImage2 = [UIImage imageNamed:@"yes2.png"];


UIImage *yesImage2Pressed = [yesImage2
stretchableImageWithLeftCapWidth:78 topCapHeight:37];

[btnYes setBackgroundImage:yesImage2Pressed
forState:UIControlStateHighlighted];
[btnYes addTarget:self action:@selector(pressAlert:)
forControlEvents:UIControlEventTouchUpInside];

[alert addSubview:btnYes];

UIButton *btnNo=[[UIButton buttonWithType:UIButtonTypeCustom]


retain];
btnNo.tag=1;
btnNo.frame = CGRectMake(200.0, 110.0, 78.0, 37.0);
btnNo.backgroundColor = [UIColor clearColor];

UIImage *noImage= [UIImage imageNamed:@"no1.png"];


UIImage *btnNoImage = [noImage
stretchableImageWithLeftCapWidth:78 topCapHeight:37];
[btnNo setBackgroundImage:btnNoImage
forState:UIControlStateNormal];

UIImage *noImage2 = [UIImage imageNamed:@"no2.png"];


UIImage *noImage2Pressed = [noImage2
stretchableImageWithLeftCapWidth:78 topCapHeight:37];

[btnNo setBackgroundImage:noImage2Pressed
forState:UIControlStateHighlighted];
[btnNo addTarget:self action:@selector(pressAlert:)
forControlEvents:UIControlEventTouchUpInside];

[alert addSubview:btnNo];
//alert.backgroundColor=[UIColor clearColor];

[alert show];

[btnNo release];
[btnYes release];

You might also like