简体   繁体   中英

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

在此处输入图片说明

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM