2011-01-08 115 views
2

我使用帶有三個按鈕的UIAlertView:「關閉」,「提交得分」和@「查看排行榜」。 UIAlertView還包含一個名爲username的UITextField。此時,UITextField「用戶名」覆蓋了UIAlertView中的其中一個按鈕。我只是想知道如何阻止UITextField覆蓋其中一個按鈕,即向下移動按鈕。TextField覆蓋UIAlertView的按鈕

這裏是發生了什麼事的形象:

screenshot http://img684.imageshack.us/img684/3055/screenshot20110108at191.png

這裏是我的代碼:

[username setBackgroundColor:[UIColor whiteColor]]; 
[username setBorderStyle:UITextBorderStyleRoundRect]; 
username.backgroundColor = [UIColor clearColor]; 
username.returnKeyType = UIReturnKeyDone; 
username.keyboardAppearance = UIKeyboardAppearanceAlert; 
username.placeholder = @"Enter your name here"; 
username = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)]; 
username.borderStyle = UITextBorderStyleRoundedRect; 
[username resignFirstResponder]; 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations" 
               message:[NSString stringWithFormat:@"You tapped %i times in %i seconds!\n", tapAmount, originalCountdownTime] 
               delegate:self 
             cancelButtonTitle:@"Dismiss" 
             otherButtonTitles:@"Submit To High Score Leaderboard", @"View Leaderboard", nil]; 
alert.tag = 01; 
[alert addSubview:username]; 
[alert show]; 
[alert release]; 

回答

3

我認爲你需要添加的一些新行和最後空間消息字符串的結尾。

[NSString stringWithFormat:@"You tapped %i times in %i seconds!\n\n\n ", tapAmount, originalCountdownTime] 
+0

謝謝,由於某種原因,仍然沒有解決它? – 2011-01-08 20:38:26

+0

你也改變了CGRectMake嗎?把他們的`origin.y`降低了? – donkim 2011-01-09 02:46:14

-1

您不應該以這種方式使用UIAlertView。從來就沒有打算對這種類型的用戶互動和視圖定製:

From the iOS Human Interface Guidelines:

您可以指定所需的標題的警報文本和可選的消息,按鈕的數量,並且按鈕的內容。您無法自定義警報視圖本身的寬度或背景外觀,或文本的對齊方式(中心對齊)。

也許考慮建立一個自定義視圖呢?

0

我有同樣的問題,你的代碼具有下列條件

[alert addSubview:username]; 
[alert show]; 

[alert show]後添加UITextfield; as

[NSString stringWithFormat:@"You tapped %i times in %i seconds!\n\n\n ", tapAmount, originalCountdownTime]; 
[alert show]; 
[alert addSubview:username]; 

這就是all.working罰款。