2013-01-11 9 views
5

私は3つのボタンとテキスト(ラベルとテキストビューではない)でalertviewを持っています。この小さなスクロールテキストとすべてのボタンがすべて一緒に詰まると、ほとんどのスペース。誰もがこれを修正する方法を知っていますか?UIALert複数のボタンをテキストで表示

答えて

7

これについてカスタムビューを作成しないのはなぜですか。

あなたは、サイズ、色、背景

をカスタマイズし、モーダルウィンドウ/ビューとして、それを表示したいとあなたが使用することができます


それでもalertViewを使用する場合のように、あなたがスペースを与えることができます:私はあなたが2 uiaertviewsを行い、その後、

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

がどのアラートビューをチェックするために使用することをお勧め

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Title" message:@"\n\n!\n\n\n\n" delegate:self cancelButtonTitle:@"Button 1" otherButtonTitles:@"Button 2",@"Button 3", nil]; 
[alert show]; 
+0

私はObjective-Cの初心者ですから、私は複数のビューを使い始めたわけではありませんが、依然として素晴らしい答えです。(投票できるといいですか?) – user1970792

+0

私の2番目の答えはどうですか? –

+0

私はそれを試してみよう – user1970792

0

クリックされました。本当にuialertviewが必要な場合は、以下の答えも素晴らしいです。

詳細:

  1. あなたのビューコントローラにuialertviewデリゲートを追加します。

    @interface ViewController : UIViewController <UIAlertViewDelegate>  
    
  2. それは次のようになります。2 alertViewsを作成:

    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"the first UIAlertView" delegate: self cancelButtonTitle:@"Back" otherButtonTitle:@"More Options", nil]; 
    

と秒OND:あなたのViewController.mで

UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"More Options" message:nil delegate:self cancelButtonTitle:@"Back" otherButtonTitle:@"Option 1", @"Option 2", @"Option 3", nil]; 
  1. 追加:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    
    if (alertView == alert1) { 
        [alert2 show]; 
    } 
    
    else if (alertView == alert2) {   
    
    NSString *string = [alertView buttonTitleAtIndex:buttonIndex]; 
    
    if ([string isEqualToString:@"Option 1"]) { 
    
        //Do stuff 
    
    } 
    else if ([string isEqualToString:@"Option 2"]) { 
    
        //Do something else 
    } 
    else if ([string isEqualToString:@"Option 3"]) { 
    
        //Do something 3rd 
    } 
    } 
    
+1

なぜ親指が落ちるのですか? – JomanJi

5

を下に表示テキストを移動するための簡単な方法は、メッセージ

[alertViewObject setMessage:@"\n"]; 

を追加することですあなたのフレームが有効になっていない理由は、-showがフレームとcrを設定することですアニメーションを開始する前にビューの階層を作成します。また、キーボードがポップアップするようにテキストビューを最初のレスポンダにする必要があります。

次のコードを使用してAlertViewをカスタマイズします。

// Customize Alert View 
UIAlertView *alertView = [UIAlertView new]; 
alertView.title = @"Alert Title"; 


// Adding Your Buttons 
[alertView addButtonWithTitle:@"Button1"]; 
[alertView addButtonWithTitle:@"Button2"]; 
[alertView addButtonWithTitle:@"Button3"]; 
[alertView addButtonWithTitle:@"Button4"]; 


// Add a Space for Text View 
alertView.message = @"\n"; 


// View heirarchy, set its frame and begin bounce animation 
[alertView show]; 


// Set the frame 
CGRect frame = alertView.frame; 
frame.origin.y -= 100.0f; 
alertView.frame = frame; 


// Adding TextField 
UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)]; 
text.borderStyle = UITextBorderStyleRoundedRect; 
[alertView addSubview:text]; 
[text becomeFirstResponder]; 

私はこれがあなたに役立つことを望みます。

+0

クール、私はそれを試してみるかもしれない! – user1970792

+0

これは素晴らしく、完璧ですが、あらかじめ書かれたメッセージが必要ですが、別の状況でそれを使用している可能性があります。時間をとってお答えしてくれてありがとう! – user1970792

+0

私は私のansを受け入れるか? –

関連する問題