版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21153627/article/details/84133726
func test1() {
let button = UIButton(type: UIButtonType.system)
button.setTitle("question", for: UIControlState())
button.frame=CGRect(x: 20, y: 120, width: 280, height:44)
button.backgroundColor=UIColor.lightGray
button.addTarget(self, action: #selector(ViewController.showAactionSheet(_ :)), for: UIControlEvents.touchUpInside)
self.view.addSubview(button)
}
@objc func showAactionSheet(_ button:UIButton){
//初始化一个警告窗口 设置标题 内容 设置窗口为动作表样式
let dialog=UIAlertController(title: "Information", message: "What's you favorite?", preferredStyle: UIAlertControllerStyle.actionSheet)
let fishing = UIAlertAction(title: "fishing", style: UIAlertActionStyle.default, handler: {(alerts:UIAlertAction) -> Void in print("I like fishing")})
let funting = UIAlertAction(title: "funting", style: UIAlertActionStyle.default, handler: {(alerts:UIAlertAction) -> Void in print("I like funting")})
let nothing = UIAlertAction(title: "noting", style: UIAlertActionStyle.default, handler: {(alerts:UIAlertAction) -> Void in print("A Life of Nonsense.")})
dialog.addAction(fishing)
dialog.addAction(funting)
dialog.addAction(nothing)
self.present(dialog,animated: true,completion: nil);
}