首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有文本字段的UIAlertView不显示字段

带有文本字段的UIAlertView不显示字段
EN

Stack Overflow用户
提问于 2016-04-07 22:35:09
回答 1查看 20关注 0票数 0

我正在尝试创建一个UIAlertView,它允许您编写注释,但字段不会出现在AlertView上。代码如下:

代码语言:javascript
复制
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

有人能帮我吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-04-07 23:01:45

从iOS8开始,UIAlertView已被弃用。此外,它也不打算以这种方式进行定制:The view hierarchy for this class is private and must not be modified. (来自文档)。

我建议要么使用众多替代库中的一个,如SDCAlertView,要么滚动您自己的评论对话框。

如果必须使用UIAlertView,请将alertViewStyle设置为UIAlertViewStyleLoginAndPasswordInput,并将密码文本字段更改为使用field.secureTextEntry = NO;显示文本

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36479411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档