2016-04-07 6 views
0

コメントを書くことができるUIAlertViewを作成しようとしていますが、フィールドはAlertViewに表示されません。ここでのコード:UIAlertView with textfield

UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Your opinion" 
               message:@"Enter your comment" // IMPORTANT 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"Send", nil]; 



textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)]; 
[textField setBackgroundColor:[UIColor blackColor]]; 
[textField setPlaceholder:@"Name"]; 
textField.keyboardAppearance = UIKeyboardAppearanceAlert; 
textField.delegate = self; 
[prompt addSubview:textField]; 

textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 50.0)]; 
[textField2 setBackgroundColor:[UIColor whiteColor]]; 
[textField2 setPlaceholder:@"Your comment"]; 
textField2.keyboardAppearance = UIKeyboardAppearanceAlert; 
textField2.delegate = self; 

lblCounter = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 120, 10)]; 
lblCounter.backgroundColor = [UIColor clearColor]; 
lblCounter.textColor = [UIColor whiteColor]; 
lblCounter.font = [UIFont systemFontOfSize:13.5]; 

lblCounter.text = @"0/100 characters"; 

[prompt addSubview:textField2]; 
[prompt addSubview:lblCounter]; 


[prompt show]; 

画像サンプル:

AlertView Sample

は、誰も私を助けてもらえますか?ありがとう

答えて

0

UIAlertViewはiOS8として廃止されました。また、この方法でカスタマイズするつもりはありません:The view hierarchy for this class is private and must not be modified.(ドキュメントから)。

SDCAlertViewのような多くの置換ライブラリの1つを使用するか、独自のコメントダイアログを使用することをお勧めします。

あなたは、UIAlertViewを使用UIAlertViewStyleLoginAndPasswordInputにalertViewStyleを設定し、field.secureTextEntry = NO;

を使用してテキストを表示するにはパスワードテキストフィールドを変更する必要がある場合