3 つのボタンとテキスト (ラベルと textView ではない) を含むアラートビューがあります。すべて一緒に詰め込むと、この小さなスクロール テキストとすべてのボタンがほとんどのスペースを占めて見苦しくなります。これを修正する方法を知っている人はいますか?
13199 次
4 に答える
7
このためのカスタム ビューを作成してみませんか。
サイズ、色、背景などを自由にカスタマイズしてご利用いただけます。
モーダルウィンドウ/ビューとして表示します。
それでも alertView を使用したい場合は、間隔を次のように指定できます。
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];
于 2013-01-11T17:54:19.223 に答える
5
テキストビューを下に移動する簡単な方法は、メッセージを追加することです
[alertViewObject setMessage:@"\n"];
フレームが有効にならない理由は、 -show がフレームを設定し、アニメーションを開始する前にビュー階層を作成するためです。また、キーボードがポップアップするように、テキスト ビューをファーストレスポンダにする必要があります。
次のコードを使用して 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];
これがお役に立てば幸いです。
于 2013-01-11T18:04:42.997 に答える
0
2 つの uiaertview を作成してから使用することをお勧めします
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
どのアラート ビューがクリックされたかを確認します。本当に uialertview が必要な場合は、以下の回答も素晴らしいです。
詳細:
ビュー コントローラーに uialertview デリゲートを追加します。
@interface ViewController : UIViewController <UIAlertViewDelegate>
2 つの alertViews を作成すると、次のようになります。
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"the first UIAlertView" delegate: self cancelButtonTitle:@"Back" otherButtonTitle:@"More Options", nil];
そして2番目:
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"More Options" message:nil delegate:self cancelButtonTitle:@"Back" otherButtonTitle:@"Option 1", @"Option 2", @"Option 3", nil];
ViewController.m に以下を追加します。
- (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 } }
于 2013-01-11T17:57:34.903 に答える