是在playground里面写吗
时间: 2024-02-20 15:01:57 浏览: 26
是的,您可以在Xcode的Playground中使用上述代码创建一个弹出窗口。以下是完整的示例代码:
```
import UIKit
import PlaygroundSupport
let alertController = UIAlertController(title: "标题", message: "消息", preferredStyle: .alert)
let okAction = UIAlertAction(title: "确定", style: .default, handler: nil)
alertController.addAction(okAction)
let viewController = UIViewController()
viewController.view.backgroundColor = .white
PlaygroundPage.current.liveView = viewController
viewController.present(alertController, animated: true, completion: nil)
```
在这个示例中,我们首先导入`UIKit`和`PlaygroundSupport`框架。然后创建了一个`UIAlertController`实例,添加了一个`UIAlertAction`实例,并将其显示出来。最后,我们创建了一个`UIViewController`实例,并将其设置为Playground的liveView,这样我们就可以在Playground中看到弹出窗口的效果了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)