Swift - 操作表(UIActionSheet)的用法,也叫底部警告框

1,下面创建一个操作表(或叫底部警告框)并弹出显示

(注:自IOS8起,建议使用UIAlertController代替UIActionSheet。)

import UIKit

class ViewController: UIViewController,UIActionSheetDelegate {

    override func viewDidLoad() {

        super.viewDidLoad()

        let actionSheet=UIActionSheet()

        //actionSheet.title = "请选择操作"

        actionSheet.addButtonWithTitle("取消")

        actionSheet.addButtonWithTitle("动作1")

        actionSheet.addButtonWithTitle("动作2")

        actionSheet.cancelButtonIndex=0

        actionSheet.delegate=self

        actionSheet.showInView(self.view);

    }

    func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {

        print("点击了:"+actionSheet.buttonTitleAtIndex(buttonIndex)!)

    }

}


2,在一般情况下,工具条,或标签条中显示的调用方式是不一样的

actionSheet.showInView(self.view); //一般情况

actionSheet.showFromToolbar(self.navigationController.toolbar) //工具条的情况下

actionSheet.showFromTabBar(self.tabBar) //标签条的情况下

图片发自简书App
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容