2011-11-18 76 views
1

enter image description here麻煩與自定義UIAlertView中在cocos2d

我想躺在背景圖像的頂部按鈕在cocos2d一個UIAlertView中。它不適用於下面的代碼。有什麼建議麼?

UIAlertView *Win=[[UIAlertView alloc] initWithTitle:@"You Win" message:nil delegate:self cancelButtonTitle:@"Next" otherButtonTitles:@"Replay",@"Quit", nil]; 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-50, -30, 400, 300)]; 

    NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"levelcleared.png"]]; 
    UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path]; 


    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 200, 70, 70)]; 

    NSString *path2= [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"alertviewhome.png"]]; 
    UIImage *bkgImg2 = [[UIImage alloc] initWithContentsOfFile:path2]; 

    imageView2. 
    [imageView setImage:bkgImg]; 
    [imageView2 setImage:bkgImg2]; 

    [bkgImg release]; 
    [path release]; 

    [Win addSubview:imageView]; 
    [Win addSubview:imageView2]; 


    [imageView release]; 


    [Win show]; 
    [Win release]; 
+1

而你的問題是什麼? –

+0

ssorry dude按下提交太快。 –

+0

所以問題在上面。它不會讓我將按鈕添加到自定義UIAlertView的背景圖像。 –

回答

1

你應該寫自己的警報樣視圖(可添加作爲一個子視圖您要顯示它在任何視圖),你想做什麼不使用UIAlertView中進行。

Apple documentation for UIAlertView說:

此類的視圖層次是私人的,不能修改。

對我來說,這意味着如果您嘗試添加子視圖(如那些按鈕或圖像或其他),您可能會有螺旋/意外/總結果。

+0

燁多數民衆贊成我剛剛讀完:(這麼傷心。使用科科斯我不認爲生病能寫我自己的警報視圖代碼。 –

+0

時,但是邁克爾說的是同樣的事情,你可以創建一個自定義你的圖形子視圖,與做同樣的事情在一個UIAlertView中的按鈕按鈕,最簡單的辦法是把在後臺木板,用三種選擇鏈接到一個單獨的行動自定義按鈕。 –

+0

@master_gracey抱歉,這是我的第一cocos2d的項目,所以我可能聽起來像一個白癡。但我很確定我不能爲它只是場景創建自定義子視圖。 –