创建一个弹出 window 只有一个 textview/string 和一个按钮 SWIFT ios 8
create a popup window with just a textview/string and a button SWIFT ios 8
我是 ios 8 和 swift 的新手,但我还没有找到一种方法来在按下按钮时制作一个简单的弹出窗口 window。我支付了教程费用,但他们仍然没有涵盖。我想要的只是当用户按下一个按钮(圆圈中的小写 i)时,一个小弹出窗口 window 带有一个文本视图,为用户提供说明,文本视图下方有一个按钮,让他们关闭弹出窗口。
到目前为止,我似乎需要的是使用 UIAlertViewController,但我看到的每个教程和示例都需要两个按钮,而且更像是一行而不是段落类型的交易。
任何人都可以告诉我如何以编程方式在 swift 中按下按钮后使弹出窗口 window 出现,并让该弹出窗口只包含一个文本视图和一个按钮,然后让该弹出窗口消失按钮被按下了吗?
听起来你想要 UIAlertController
,看看这个:
@IBAction func popUpButton(sender: UIButton) {
//This is where you declare and initialize your `UIAlertController`
let alertController = UIAlertController(title: "Alert", message: "Test Alert", preferredStyle: .Alert)
//You give the `UIAlertController` an action, which basically has a cancel button, that just cancels out the popup
alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
//this actually gets the `UIAlertController` on your screen when the button is pressed
self.presentViewController(alertController, animated: true, completion: nil)
}
提示
确保您通过 Main.storyboard[=26= 正确地 link 将您的按钮向上 ViewController
]
我是 ios 8 和 swift 的新手,但我还没有找到一种方法来在按下按钮时制作一个简单的弹出窗口 window。我支付了教程费用,但他们仍然没有涵盖。我想要的只是当用户按下一个按钮(圆圈中的小写 i)时,一个小弹出窗口 window 带有一个文本视图,为用户提供说明,文本视图下方有一个按钮,让他们关闭弹出窗口。
到目前为止,我似乎需要的是使用 UIAlertViewController,但我看到的每个教程和示例都需要两个按钮,而且更像是一行而不是段落类型的交易。
任何人都可以告诉我如何以编程方式在 swift 中按下按钮后使弹出窗口 window 出现,并让该弹出窗口只包含一个文本视图和一个按钮,然后让该弹出窗口消失按钮被按下了吗?
听起来你想要 UIAlertController
,看看这个:
@IBAction func popUpButton(sender: UIButton) {
//This is where you declare and initialize your `UIAlertController`
let alertController = UIAlertController(title: "Alert", message: "Test Alert", preferredStyle: .Alert)
//You give the `UIAlertController` an action, which basically has a cancel button, that just cancels out the popup
alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
//this actually gets the `UIAlertController` on your screen when the button is pressed
self.presentViewController(alertController, animated: true, completion: nil)
}
提示
确保您通过 Main.storyboard[=26= 正确地 link 将您的按钮向上 ViewController
]