我创建自定义警报视图使用背景图像和一个按钮(以关闭警报视图)。但按钮操作未调用
这是我的代码。
在.h文件中
UIAlertView *alert;
在.m文件中
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];
以下是解除警报的代码
- (IBAction)buttonClicked:(id)sender
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
有人请帮帮忙。提前致谢答案 0 :(得分:1)
你在自定义子类UIView中创建这样的东西,并在需要时调用它。 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;