//? ? 定義button
let centerBtn = UIButton(frame:CGRectMake(view.frame.size.width/2-50,100,100,50))
centerBtn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
centerBtn.setTitle("中部彈出框", forState: UIControlState.Normal)
centerBtn.backgroundColor = UIColor.orangeColor()
centerBtn.addTarget(self, action: #selector(ViewController.centerBtnClicked), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(centerBtn)
//? ? ? 定義button
let bottomBtn = UIButton(frame:CGRectMake(view.frame.size.width/2-50,200,100,50))
bottomBtn.backgroundColor = UIColor.brownColor()
bottomBtn.setTitle("底部彈出框", forState: UIControlState.Normal)
bottomBtn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
bottomBtn.addTarget(self, action: #selector(ViewController.bottomBtnClicked), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(bottomBtn)
}
//? ? 底部彈出框
func bottomBtnClicked(){
let alertSheet = UIAlertController.init(title: "分享", message: nil,preferredStyle: .ActionSheet)
let alertSheetAction = UIAlertAction.init(title: "朋友圈分享",style: .Default,handler:? {(UIAlertAction) ->Void in
print("朋友圈分享")
})
let alertSheetDestructive = UIAlertAction.init(title: "QQ分享",style: .Default,handler: {(UIAlertAction) ->Void in
print("QQ分享")
})
let alertSheetCancel = UIAlertAction.init(title: "取消", style: .Cancel,handler: {(UIAlertAction) ->Void in
print("取消")
})
alertSheet.addAction(alertSheetAction)
alertSheet.addAction(alertSheetDestructive)
alertSheet.addAction(alertSheetCancel)
self.presentViewController(alertSheet, animated: true, completion: nil)
}
//中部彈出框
func centerBtnClicked(){
//? ? 中間彈出效果
let alertView: UIAlertController = UIAlertController.init(title: "提示", message: "是否要更新", preferredStyle: UIAlertControllerStyle.Alert)
let alertViewDefaultAction: UIAlertAction = UIAlertAction.init(title: "確定", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
print("正在更新")
})
let alertViewCanceltAction: UIAlertAction = UIAlertAction.init(title: "取消", style: UIAlertActionStyle.Cancel, handler: { (UIAlertAction) -> Void in
print("取消更新")
})
//? ? ? ? 紅色的字體
let alertViewDestructiveAction: UIAlertAction = UIAlertAction.init(title: "銷毀",style: UIAlertActionStyle.Destructive, handler: {(UIAlertAction) -> Void in
print("已經(jīng)銷毀掉了")
} )
//? ? ? ? 用戶名
alertView.addTextFieldWithConfigurationHandler({(UITextField) -> Void in
UITextField.placeholder = "name"
UITextField.clearButtonMode = UITextFieldViewMode.WhileEditing
})
//? ? ? ? 密碼
alertView.addTextFieldWithConfigurationHandler({(UITextField) -> Void in
UITextField.placeholder = "password"
UITextField.clearButtonMode = UITextFieldViewMode.WhileEditing
})
alertView.addAction(alertViewDefaultAction)
alertView.addAction(alertViewCanceltAction)
alertView.addAction(alertViewDestructiveAction)
self.presentViewController(alertView, animated:true , completion: nil)
}