如何将 TextField 放入 AlertView 中?

发布于 2024-12-17 07:36:12 字数 418 浏览 1 评论 0原文

可能的重复:
iPhone 上 UIAlertView 中的 UITextField - 如何使其响应?
UIAlertView 中的 UITextField 替代方案?

我想在向用户显示警报时将 TextField 放入 AlertView 中。

Possible Duplicate:
UITextField in UIAlertView on iPhone - how to make it responsive?
UITextField in UIAlertView alternative?

i want to put TextField in AlertView when the alert is displayed to the users.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

鯉魚旗 2024-12-24 07:36:12

从 iOS5 开始,您可以使用 UIAlertViewStyle 将不同的 Textinput 添加到 UIAlertview

示例链接

Since iOS5 you can use UIAlertViewStyle to add the different Textinput into the UIAlertview

Example Link

薄荷港 2024-12-24 07:36:12

来自 iPhone 上 UIAlertView 中的 UITextField - 如何使其响应?

UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];

from UITextField in UIAlertView on iPhone - how to make it responsive?

UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
多情癖 2024-12-24 07:36:12

只需将其作为 subView 添加到具有您想要的帧大小的 UIAlertView 对象即可!

Just add it as a subView to the UIAlertView object with the frame size that you desire !

盗心人 2024-12-24 07:36:12

我想出了这个,有点长,但我设置了它然后忘记了,它有效......

alertView = [[UIAlertView alloc] initWithTitle:t message:@"" delegate:self     cancelButtonTitle:@"CANCEL" otherButtonTitles:@"OK", nil];

pinField = [[UITextField alloc] initWithFrame:CGRectMake(20, 38, 244, 31)];
pinField.backgroundColor = [UIColor whiteColor];
[alertView show];


[alertView insertSubview:pinField atIndex:2];


NSArray * subviews = [alertView subviews];
UILabel * label1 = [subviews objectAtIndex:1];
UIImageView * bg = [subviews objectAtIndex:0];
UIView * button1 = [subviews objectAtIndex:4];
UIView * button2 = [subviews objectAtIndex:5];
float height = 0;
height = 16 + label1.frame.size.height;
CGRect frame = label1.frame;
frame.origin.y = 8;
label1.frame = frame;

frame = pinField.frame;
frame.origin.y = height;
pinField.frame = frame;

height += 8 + frame.size.height;
frame = button1.frame;
frame.origin.y = height;
button1.frame = frame;

frame = button2.frame;
frame.origin.y = height;
button2.frame = frame;

height += 8 + frame.size.height;
frame = alertView.frame;
frame.size.height = height +8;
alertView.frame= frame;

frame = bg.frame;
frame.size.height = alertView.frame.size.height;
bg.frame = frame;

[pinField release];
[alertView release];

I came up with this, its a little long, but I set it and forgot and it works...

alertView = [[UIAlertView alloc] initWithTitle:t message:@"" delegate:self     cancelButtonTitle:@"CANCEL" otherButtonTitles:@"OK", nil];

pinField = [[UITextField alloc] initWithFrame:CGRectMake(20, 38, 244, 31)];
pinField.backgroundColor = [UIColor whiteColor];
[alertView show];


[alertView insertSubview:pinField atIndex:2];


NSArray * subviews = [alertView subviews];
UILabel * label1 = [subviews objectAtIndex:1];
UIImageView * bg = [subviews objectAtIndex:0];
UIView * button1 = [subviews objectAtIndex:4];
UIView * button2 = [subviews objectAtIndex:5];
float height = 0;
height = 16 + label1.frame.size.height;
CGRect frame = label1.frame;
frame.origin.y = 8;
label1.frame = frame;

frame = pinField.frame;
frame.origin.y = height;
pinField.frame = frame;

height += 8 + frame.size.height;
frame = button1.frame;
frame.origin.y = height;
button1.frame = frame;

frame = button2.frame;
frame.origin.y = height;
button2.frame = frame;

height += 8 + frame.size.height;
frame = alertView.frame;
frame.size.height = height +8;
alertView.frame= frame;

frame = bg.frame;
frame.size.height = alertView.frame.size.height;
bg.frame = frame;

[pinField release];
[alertView release];
ゞ花落谁相伴 2024-12-24 07:36:12
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Save As" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[self.textfield setBackgroundColor:[UIColor whiteColor]];

[myAlertView addSubview:self.textfield];
[myAlertView show];
[myAlertView release];
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Save As" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[self.textfield setBackgroundColor:[UIColor whiteColor]];

[myAlertView addSubview:self.textfield];
[myAlertView show];
[myAlertView release];
如梦初醒的夏天 2024-12-24 07:36:12
UIAlertView *customAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

[txtField setBackgroundColor:[UIColor whiteColor]];

[customAlertView addSubview:txtField];

[customAlertView show];

[customAlertView release];
UIAlertView *customAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

[txtField setBackgroundColor:[UIColor whiteColor]];

[customAlertView addSubview:txtField];

[customAlertView show];

[customAlertView release];
揽清风入怀 2024-12-24 07:36:12

创建一个继承自 UIAlertview 的自定义类并向其添加一个文本字段元素。

然后写这个方法:

-(id)init
{
    txtField = [[UITextField alloc] initWithFrame: CGRectZero]; // your frame here
    [self addSubview: txtField];

    return self;
}

这可能会有所帮助。
现在在其他类中创建此类的对象并测试它。

Create a custom class which inherits from UIAlertview and add a textfield element to it.

Then write this method :

-(id)init
{
    txtField = [[UITextField alloc] initWithFrame: CGRectZero]; // your frame here
    [self addSubview: txtField];

    return self;
}

This might help.
Now create an object of this class in some other class and test it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文