UIALertView带有文本的多个按钮

use*_*792 5 iphone xcode button alertview

我有一个带有3个按钮和文本的警报视图(标签而不是textView)如果我将它们全部卡在一起,这个微小的滚动文本和占据大部分空间的所有按钮都会变得难看.有谁知道如何解决这一问题?

Ano*_*dya 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];
Run Code Online (Sandbox Code Playgroud)


Sat*_*zad 5

向下移动文本视图的一种简单方法是添加消息

[alertViewObject setMessage:@"\n"];
Run Code Online (Sandbox Code Playgroud)

您的框架未生效的原因是-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]; 
Run Code Online (Sandbox Code Playgroud)

我希望这能帮到您.