Siba Prasad Hota
Siba Prasad Hota

Reputation: 4789

Custom Alertview Button Action not calling

I m Creating a custom alertview With Background image and one button (to dismiss the alert view).But the button action is not calling

enter image description here

here is my code.

In .h file

UIAlertView *alert;

In .m file

alert = [[UIAlertView alloc] init];

            [alert setTitle:nil];
            [alert setMessage:nil];
            [alert setDelegate:self];


            UIImage *alertImage = [UIImage imageNamed:@"stopthegame.png"];
            UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage :alertImage];

            backgroundImageView.frame = CGRectMake(0, 0, 282, 160);

            backgroundImageView.contentMode = UIViewContentModeScaleToFill;

            [alert addSubview:backgroundImageView];




   UIButton *alertok = [UIButton buttonWithType:UIButtonTypeCustom];


            alertok.frame = CGRectMake(105, 110, 75,40);

            UIImage *buttonImageNormal = [UIImage imageNamed:@"yesorno.png"];
            UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
            [alertok setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
            UIImage *buttonImagePressed = [UIImage imageNamed:@"instructionok.png"];
            UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
            [alertok setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];

            [alertok setTitle:@"OK" forState:UIControlStateNormal];
            [alertok setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];


           [alert addSubview:alertok ]; 

[alertok addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];



 [alert show];

Here is the code to dismiss the alert

- (IBAction)buttonClicked:(id)sender
{

    [alert dismissWithClickedButtonIndex:0 animated:YES];

}

some one please help. Thanks in advance

Upvotes: 1

Views: 279

Answers (1)

FreeAppl3
FreeAppl3

Reputation: 858

Something like this you create in a custom subclass UIView and call it out when needed. https://github.com/FreeApple/CustomAlertView

+(void)showCustomPop:(CustomAlertViewType)type inView:(UIView*)view WithTitle:(NSString    
*)title Message:(NSString *)message  actionButtonTitle:(NSString*)actionTitle 
action:(void*)sel cancelButtonTitle:(NSString *)cancelTitle;

Upvotes: 1

Related Questions