我需要在iphone项目的alert view的2个默认按钮下插入一个视图(一个自定义按钮)。 我搜索了很久,但我没有找到如何在按钮下插入元素,提示?将元素添加到UIAlertview
1
A
回答
0
不完全清楚你想要做什么,但有几种可能性。如果你只是想要常规的按钮,你可以使用其他按钮参数来粘贴尽可能多的按钮。
UIAlertView* anAlert = [[UIAlertView alloc] initWithTitle:@"My Alert" message:@"This is My Alert" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Other", @"Other2", nil];
您还可以使用addButtonWithTitle添加任意多的。
UIAlertView* anAlert = [[UIAlertView alloc] initWithTitle:@"My Alert" message:@"This is My Alert" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"OK", nil];
[anAlert addButtonWithTitle:@"My Other Button"];
如果你真的想要一个自定义按钮,事情会变得更加棘手。干扰任意观看UIAlertViews是我的一个爱好(请参阅我的博客文章主题here和here和here)。但是,在所有这些情况下,观看结果都在正常按钮之上。按钮固定在视图的底部,我知道无法改变这种行为。
你可以做的一件事是创建没有按钮的UIAlertView,然后创建并添加尽可能多的自定义按钮。首先,我想指出,这可能是一个坏主意。这不会是一个很好的用户体验,除非你是TapBots,坚持Apple's HIG通常是一个好主意。
说了这么多,这样的事情可能工作:
UIAlertView* anAlert = [[UIAlertView alloc] initWithTitle:@"My Alert" message:@"This is My Alert\n\n\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIButton* okButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
okButton.frame = CGRectMake(12, 80, 130, 50);
[okButton setTitle:@"OK" forState:UIControlStateNormal];
[anAlert addSubview:okButton];
UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelButton.frame = CGRectMake(144, 80, 130, 50);
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[anAlert addSubview:cancelButton];
UIButton* otherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
otherButton.frame = CGRectMake(12, 136, 260, 50);
[otherButton setTitle:@"My Other Button" forState:UIControlStateNormal];
[anAlert addSubview:otherButton];
在警报消息末尾的换行符水平扩展的警报视图,使居室增添你的按钮。在这里,我只是在做简单的UIButtons(看起来很可怕);希望你的自定义按钮看起来更好。您需要通过对坐标进行硬编码(这些坐标很脆弱(并根据您的消息和屏幕方向进行更改)来自行布局)。最后,由于没有任何默认按钮,因此无法解除警报,所以您必须确保在这些按钮上粘贴处理程序才能实现此目的。您可以通过按钮上的addTarget:action:forControlEvents:
进行此操作。
相关问题
- 1. 将UIActionsheet添加到UIAlertView中
- 2. 将TextField添加到UIAlertView
- 3. 将UIWebView添加到UIAlertView iOS
- 4. Angular2将元素添加到元素
- 5. 将MouseOverHandler添加到元素?
- 6. 将元素添加到JPanel
- 7. 如何将UITableView添加到UIAlertView?
- 8. 如何将UIScrollView添加到UIAlertView
- 9. 将活动指示器添加到UIAlertView
- 10. 如何将userInfo添加到UIAlertView?
- 11. 如何将图像添加到UIAlertView?
- 12. 将文本框添加到UIAlertView
- 13. 如何将`accessibilityLabel`添加到`UIAlertView`按钮?
- 14. 添加到的UITextField UIAlertView中
- 15. 如何将元素添加到DOM
- 16. 将一个类添加到“this”元素
- 17. 将JS添加到body元素
- 18. 将元素添加到结构阵列
- 19. JQuery将类添加到父元素
- 20. 将纹理添加到二维元素
- 21. 将元素添加到fifo队列
- 22. 如何将元素添加到集合
- 23. 将类添加到html元素动态
- 24. Python XML将元素添加到文件
- 25. 将ID添加到Fabric.js元素
- 26. jQuery - 将元素添加到数组
- 27. 将图像添加到Array.push元素
- 28. 将属性添加到DOM元素
- 29. 如何将元素添加到BSONArray?
- 30. 将元素添加到阵列
除非您想使用'otherButtonTitles'添加按钮,否则如果您需要更好的东西,您可能需要考虑推出自己的按钮。同样,它可能很难说是否可以接受AppStore。 – 2011-05-13 07:57:54
看看这个链接可能有帮助 http://stackoverflow.com/questions/5576031/iphone-alertview-with-textfield – 2011-05-13 07:55:47