一编整、UIAlertController 提示介紹
提示缰儿,在App中許多地方用到提示和用戶進(jìn)行交互。讓用戶進(jìn)行自己的選擇露泊。
二喉镰、UIAlertController---> Alert 的使用和方法
1、 Alert 的初始化
/**
初始化
*/
NwAlertView = UIAlertController.init()
/**
彈出提示的類型
UIAlertControllerStyle
alert : 簡(jiǎn)單的塊型提示惭笑。
actionSheet : 是一種列表型的提示
*/
NwAlertView = UIAlertController.init(title: "選一選", message: "你想要哪個(gè)美女侣姆?", preferredStyle: .alert)
2、添加交互
/**
添加交互
UIAlertActionStyle 交互的類型
cancel : 取消提示
default : 默認(rèn)提示藍(lán)色字體
destructive : 按鈕字體顏色為紅色
*/
let DeleteAction = UIAlertAction.init(title: "刪除", style: .cancel) { (UIAlertAction) in
print("放棄選擇")
}
let SureAction = UIAlertAction.init(title: "確定", style: .destructive) { (UIAlertAction) in
print("確定選擇")
}
/**
添加到提示上
*/
NwAlertView.addAction(DeleteAction)
NwAlertView.addAction(SureAction)
3沉噩、進(jìn)行彈出展示
self.present(self.NwAlertView, animated: true, completion: nil)
展示的效果圖如下:
有兩種形式
4捺宗、友情鏈接之老版本的提示寫法
let oldAlertView = UIAlertView.init(title: "美女", message: "請(qǐng)選擇你心儀的哪一位", delegate: self, cancelButtonTitle: "取消")
oldAlertView.addButton(withTitle: "確定")
oldAlertView.show()
代理事件
// TODO: 老的寫法的代理事件
func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
print("我選擇"+"\(buttonIndex)")
}
三、UIAlertController---> ActionSheet 的使用和方法
1川蒙、初始化
NwAlertView = UIAlertController.init(title: "選一選", message: "你挑選哪一位美女蚜厉?", preferredStyle: .actionSheet)
2、添加交互
/**
添加其他按鈕
*/
let Action1 = UIAlertAction.init(title: "貂蟬", style: .default) { (UIAlertAction) in
print("我選擇貂蟬")
}
NwAlertView.addAction(Action1)
let Action2 = UIAlertAction.init(title: "西施", style: .default) { (UIAlertAction) in
print("我選擇西施")
}
NwAlertView.addAction(Action2)
/**
添加清楚按鈕
*/
let DeleteAction = UIAlertAction.init(title: "取消", style: .cancel) { (DeleteAction) in
}
/**
添加到提示窗上
*/
NwAlertView.addAction(DeleteAction)
3畜眨、渲染到視圖上
self.present(self.NwAlertView, animated: true, completion: nil)
效果展示圖:
4昼牛、友情鏈接之老 ActionSheet的創(chuàng)建
let oldActionSheet = UIActionSheet.init(title: "挑美女", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "選定")
oldActionSheet.addButton(withTitle: "就是你吧")
oldActionSheet.show(in: self.view)
代理事件
func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int) {
print("我的選擇ActionSheet"+"\(buttonIndex)")
}
效果展示: