Swift 是一種簡單易學的程式語言,它可以讓開發者快速開發出功能強大的應用程式。在 Swift 中,UIAlertController 和 ActionSheet 是兩種常見的選擇方式,可以讓開發者在應用程式中提供多種選擇。

UIAlertController 是一種提供使用者多種選擇的方式,它可以讓使用者在應用程式中選擇不同的操作。它可以讓開發者在應用程式中提供多種選擇,例如:取消、確定、重試等等。

使用 UIAlertController 的程式範例

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

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)

alertController.addAction(cancelAction)
alertController.addAction(okAction)

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

ActionSheet 是一種提供使用者多種選擇的方式,它可以讓使用者在應用程式中選擇不同的操作。它可以讓開發者在應用程式中提供多種選擇,例如:取消、確定、重試等等。

使用 ActionSheet 的程式範例

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

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)

actionSheet.addAction(cancelAction)
actionSheet.addAction(okAction)

present(actionSheet, animated: true, completion: nil)

總結來說,Swift UIAlertController 和 ActionSheet 都是可以讓開發者在應用程式中提供多種選擇的方式,可以讓使用者在應用程式中選擇不同的操作。開發者可以根據自己的需求來選擇適合的方式,以提供更好的使用者體驗。

推薦閱讀文章

推薦閱讀文章

            <a href="https://www.raywenderlich.com/749224-getting-started-with-swiftui-alerts-and-action-sheets">Getting Started with SwiftUI Alerts and Action Sheets</a><br>
            <a href="https://www.hackingwithswift.com/quick-start/swiftui/how-to-use-alerts-and-action-sheets-in-swiftui">How to use alerts and action sheets in SwiftUI</a><br>
            <a href="https://www.appcoda.com/swiftui-alerts/">How to Create Alerts and Action Sheets in SwiftUI</a><br>
            <a href="https://www.iosapptemplates.com/blog/swift-programming/swiftui-alerts-action-sheets">SwiftUI Alerts & Action Sheets</a><br>
            <a href="https://www.appcoda.com/swiftui-action-sheet/">How to Create Action Sheets in SwiftUI</a

延伸閱讀本站文章

更多swift相關文章

Swift UIAlertController + ActionSheet 💡選擇的時候有多種方法!

Categorized in:

Tagged in:

,