views:

915

answers:

2
+1  Q: 

Custom Alert view

hi, I want to create a custom alert view, i.e. i want to put some images and my choice color on alert view, i know how to create normal alert view, but can any one help me out in this one??? so that the application will look pretty good.

regard viral.

+1  A: 

You'll need to create your own custom view, and implement some alert view style behaviour, such as displaying modally, dimming the background, animating in and out, etc.

There's no support in the SDK for customising a UIAlertView any further than the text or buttons.

Jasarien
So I m suppose to create my own view and den display it as if it were a alert view, right???fine thanks for ur suggestion ...
iPhone Fun
+1  A: 

I set up my own UIViewController which I can skin with my own images. I generally only use one or two buttons, so I hide the second button if it's not being used. The view is actually the size of the entire screen, so it blocks touches behind it, but it is mostly transparent, so the background shows through.

When bringing it in, I use a few animations to make it bounce like Apple's alert view. Something like this works:

-(void)initialDelayEnded {
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
    self.view.alpha = 1.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/1.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    [UIView commitAnimations];
}

- (void)bounce1AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)];
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
    [UIView commitAnimations];
}

- (void)bounce2AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    self.view.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}

I have the possibility of a short delay built into the class, so initialDelayEnded is called when that delay is over.

When initializing, I pass in an object and selector I want called when each button is pressed, and then I call the appropriate selector on the object when a button is pressed.

Nathan S.
Thanks buddy ...for ur nice support, now let me implement den reply u....thanks again...
iPhone Fun
YEA, it's working in the same manner as i was wanted.. thanks..
iPhone Fun