
iphone
Swift// 创建一个按钮let button = UIButton(type: .system)button.setTitle("点击弹出菜单", for: .normal)button.addTarget(self, action: #selector(showPopupMenu), for: .touchUpInside)self.view.addSubview(button)// 弹出菜单的触发方法@objc func showPopupMenu() { let alertController = UIAlertController(title: "选择操作", message: nil, preferredStyle: .actionSheet) alertController.addAction(UIAlertAction(title: "选项一", style: .default, handler: { (_) in // 处理选项一的操作 })) alertController.addAction(UIAlertAction(title: "选项二", style: .default, handler: { (_) in // 处理选项二的操作 })) alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil)) if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = button popoverController.sourceRect = button.bounds } self.present(alertController, animated: true, completion: nil)}以上是关于 iphone 弹出菜单和 iPad 弹出菜单的简单介绍和一个案例代码。无论是 iphone 还是 iPad,弹出菜单都是提供了方便快捷的操作方式,帮助用户更高效地完成任务。根据设备的不同特点,我们可以灵活地设计和定制弹出菜单,以提供更好的用户体验。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号