ios里的UIActionSheet的使用

class ViewController: UIViewController,UIActionSheetDelegate{
    @IBOutlet weak var label1: UILabel!

    @IBAction func button1(sender: UIButton) {
        let actionSheet1 = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "取消分享", destructiveButtonTitle: "分享到新浪微博", otherButtonTitles: "分享到QQ空间")
        
        actionSheet1.showInView(self.view)
        
    }
    func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
        label1.text = actionSheet.buttonTitleAtIndex(buttonIndex)
    }
    
    @IBAction func button2(sender: UIButton) {
        
        let alertController = UIAlertController(title: "标题", message: "这个是UIAlertController的默认样式", preferredStyle: UIAlertControllerStyle.Alert)
        let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
        let okAction = UIAlertAction(title: "好的", style: .Default, handler: nil)
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        self.presentViewController(alertController, animated: true, completion: nil)
        }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

posted on 2016-01-08 10:28  子墨'  阅读(169)  评论(0编辑  收藏  举报

导航