Swift UIAlertController警告視窗使用 🚨

Swift 是一種用於開發 iOS、macOS、watchOS 和 tvOS 應用程式的開放源碼程式語言。它是由 Apple 開發的,用於替代 Objective-C 語言。在 Swift 中,UIAlertController 是一個非常有用的工具,可以用於在 iOS 應用程式中創建警告視窗。

UIAlertController 可以用於向用戶顯示警告消息,並提供一個或多個按鈕供用戶選擇。它可以用於提示用戶輸入信息,提供選擇,或者提供一個操作按鈕。

要在 Swift 中創建 UIAlertController,首先需要創建一個 UIAlertController 對象,並指定標題和消息:

let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)

接下來,可以添加一個或多個按鈕,以便用戶可以選擇:

let action1 = UIAlertAction(title: "Option 1", style: .default) { (action:UIAlertAction) in
    print("Option 1 selected")
}
let action2 = UIAlertAction(title: "Option 2", style: .default) { (action:UIAlertAction) in
    print("Option 2 selected")
}
alertController.addAction(action1)
alertController.addAction(action2)

最後,可以將 UIAlertController 顯示給用戶:

self.present(alertController, animated: true, completion: nil)

UIAlertController 是一個非常有用的工具,可以用於在 iOS 應用程式中創建警告視窗。它可以用於提示用戶輸入信息,提供選擇,或者提供一個操作按鈕。使用 Swift 中的 UIAlertController 可以輕鬆快速地創建警告視窗,並提供用戶可以選擇的按鈕。

推薦閱讀文章

推薦閱讀文章

            <a href="https://www.raywenderlich.com/749224-uialertcontroller-tutorial-getting-started">Raywenderlich - UIAlertController Tutorial: Getting Started</a><br>
            <a href="https://www.hackingwithswift.com/example-code/uikit/how-to-use-uialertcontroller">Hacking with Swift - How to use UIAlertController</a><br>
            <a href="https://www.appcoda.com/uialertcontroller-swift-closures-enum/">AppCoda - UIAlertController Tutorial: How to Use Closures and Enums</a><br>
            <a href="https://www.ioscreator.com/tutorials/uialertcontroller-ios-tutorial">iOS Creator - UIAlertController Tutorial</a><br>
            <a href="https://www.iosapptemplates.com/blog/swift-programming/uialertcontroller-swift-example">iOS App Templates - UIAlertController Swift Example</a

延伸閱讀本站文章

更多swift相關文章

Swift UIAlertController警告視窗使用 🚨

Categorized in:

Tagged in:

,