gpt4 book ai didi

ios - 创建类似于邮件应用程序菜单的 iPhone 弹出菜单

转载 作者:IT王子 更新时间:2023-10-29 08:02:03 24 4
gpt4 key购买 nike

当您想回复邮件时,我想创建一个类似于邮件应用程序中的弹出菜单。我在不止一个应用程序中看到过这种情况,所以我不确定框架中是否内置了一些东西或那里有一些示例代码。

UIActionSheet example

最佳答案

在 Swift 中创建操作表

代码已通过 Swift 5 测试

enter image description here

自 iOS 8 起,UIAlertControllerUIAlertControllerStyle.ActionSheet 结合使用。 UIActionSheet 已弃用。

下面是生成上图中操作表的代码:

class ViewController: UIViewController {

@IBOutlet weak var showActionSheetButton: UIButton!

@IBAction func showActionSheetButtonTapped(sender: UIButton) {

// Create the action sheet
let myActionSheet = UIAlertController(title: "Color", message: "What color would you like?", preferredStyle: UIAlertController.Style.actionSheet)

// blue action button
let blueAction = UIAlertAction(title: "Blue", style: UIAlertAction.Style.default) { (action) in
print("Blue action button tapped")
}

// red action button
let redAction = UIAlertAction(title: "Red", style: UIAlertAction.Style.default) { (action) in
print("Red action button tapped")
}

// yellow action button
let yellowAction = UIAlertAction(title: "Yellow", style: UIAlertAction.Style.default) { (action) in
print("Yellow action button tapped")
}

// cancel action button
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
print("Cancel action button tapped")
}

// add action buttons to action sheet
myActionSheet.addAction(blueAction)
myActionSheet.addAction(redAction)
myActionSheet.addAction(yellowAction)
myActionSheet.addAction(cancelAction)

// present the action sheet
self.present(myActionSheet, animated: true, completion: nil)
}
}

还需要帮助吗?观看此视频教程。我就是这样学的。

关于ios - 创建类似于邮件应用程序菜单的 iPhone 弹出菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/911137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com