Set Timer In Alert View.
Set Timer in alert view on the position of cancel button
- (IBAction)okButtonClicked:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Pay successfully !" message:@"Ok" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"",nil];
[alert show];
//make label and make it subView of alert
timeLabel= [[UILabel alloc] initWithFrame:CGRectMake(200 , 82, 120, 40 )];
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];
[alert addSubview:timeLabel];
//start timer
NSTimer *timer = [[NSTimer alloc] init];
timer = [NSTimer timerWithTimeInterval:1.0 target:self
selector:@selector(timeSet:) userInfo:timer repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode: NSDefaultRunLoopMode];
}
-(void)timeSet : (id)sender
{
static int i2 = 10;
timeLabel.text = [NSString stringWithFormat:@"%d",i2];
if (i2==0)
{
[sender invalidate];
//other task you want to do after time reach to zero
}
i2--;
}
Comments
Post a Comment