2012-03-27 58 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

相關問題