如何在Swift中向UIAlertView添加TextField [英] How to add a TextField to UIAlertView in Swift
本文介绍了如何在Swift中向UIAlertView添加TextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,但我不知道如何在UIAlertView中显示文本字段。
I have this code, but I dont know how to show a textfield inside the UIAlertView.
var altMessage = UIAlertController(title: "Warning", message: "This is Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
altMessage.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(altMessage, animated: true, completion: nil)
我有这个代码textfield,如何在UIAlerView中显示
I have this code for textfield , how can I show this in UIAlerView
var my:UITextField = UITextField(frame: CGRectMake(0, 0, 10, 10))
我也试过这段代码:
I also tried this code:
var alert = UIAlertView()
alert.title = "Enter Input"
alert.addButtonWithTitle("Done")
alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
alert.addButtonWithTitle("Cancel")
alert.show()
当我指定AlertSt时yle plainText,它显示一个带默认占位符的TextField,Login..我想改变它,我想显示一个Decimal Pad键盘。我还想处理用户输入textField的值。有人可以帮我吗?
When I specify the AlertStyle plainText, it shows a TextField with default placeholder, "Login".. I want to change that, I want to show a Keyboard of Decimal Pad. I also want to handle the value the user enters into the textField. Can someone help me with this?
推荐答案
您可以访问文本字段:
let textField = alert.textFieldAtIndex(0)
然后更改占位符文本:
textField.placeholder = "Foo!"
键盘类型:
textField.keyboardType = ...
这篇关于如何在Swift中向UIAlertView添加TextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文