2012-03-27 81 views
1

余米创建自定义alertview随着背景图像和一个按钮自定义Alertview按钮操作(以关闭警报视图),但该按钮的动作并没有叫没有要求

enter image description here

这里是我的代码。

在.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

还有一个疑问:苹果是否会接受这个自定义警报视图? – 2012-03-27 14:36:36

+0

为什么你需要一个按钮来解除UIAlertView如果你有本地的? – fabregas88 2012-03-27 14:46:07

+0

buttonClicked:方法实际上没有被调用,或者是没有被解雇的警报? – rosslebeau 2012-03-27 14:47:16

回答

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; 
+0

谢谢你的答案,但你可以请澄清一些示例代码? – 2012-04-17 17:27:34

+0

我可以做得更好....这是我建立的一个示例项目。我不会把这个发布给公众,让他们只用在他们的项目中,但是他们可以从我学到的东西中学习。如果您决定在任何项目中使用此代码或代码,请在哪里做适当的评分。这里是项目https://github.com/FreeApple/CustomAlertView – FreeAppl3 2012-04-17 23:28:45

相关问题