美文网首页
swift 4.2实现操作表(ULAlertController

swift 4.2实现操作表(ULAlertController

作者: yytester | 来源:发表于2019-01-08 10:26 被阅读10次
    import UIKit
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            
            let screen = UIScreen.main.bounds
            let buttonActionSheet = UIButton(type: UIButton.ButtonType.system)
            buttonActionSheet.setTitle("Test操作表", for: UIControl.State())
            
            let buttonActionSheetWidth :CGFloat = 100
            let buttonActionSheetHeight :CGFloat = 30
            let buttonActionSheetTopView :CGFloat = 260
            
            buttonActionSheet.frame = CGRect(x: (screen.size.width - buttonActionSheetWidth)/2, y: buttonActionSheetTopView, width: buttonActionSheetWidth, height: buttonActionSheetHeight)
            buttonActionSheet.addTarget(self, action: #selector(testActionSheet(_:)), for: .touchUpInside)
            self.view.addSubview(buttonActionSheet)
             
        }
        
        
        
        @objc func testActionSheet(_ sender:AnyObject){
            
            let actionSheetController = UIAlertController()
            
            let cancelAction = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) {(UIAlertAction) -> Void in
                print("Tap 取消 Button")
            }
            let destructiveAction = UIAlertAction(title: "破坏性按钮", style: UIAlertAction.Style.destructive) {(UIAlertAction) -> Void in
                print("Tap 破坏性按钮 Button")
            }
            let otherAction = UIAlertAction(title: "新浪微博", style: UIAlertAction.Style.default) {(UIAlertAction) -> Void in
                print("Tap 新浪微博 Button")
            }
            actionSheetController.addAction(cancelAction)
            actionSheetController.addAction(destructiveAction)
            actionSheetController.addAction(otherAction)
            
            actionSheetController.popoverPresentationController?.sourceView = sender as? UIView
            
            self.present(actionSheetController,animated: true,completion: nil)
            
        }
        
    
    
    }
    
    image.png

    相关文章

      网友评论

          本文标题:swift 4.2实现操作表(ULAlertController

          本文链接:https://www.haomeiwen.com/subject/iacvrqtx.html