前幾天寫(xiě)了菊花,后來(lái)發(fā)現(xiàn)還缺個(gè)彈窗粱檀,于是乎寫(xiě)了簡(jiǎn)單的彈窗洲敢。到目前為止,項(xiàng)目中遇到的彈窗還沒(méi)有要求說(shuō)有輸入框的茄蚯,所以寫(xiě)了個(gè)簡(jiǎn)簡(jiǎn)單單的彈窗压彭。代碼放到github了,RAlertView --- 彈窗 https://github.com/ray1942/RAlertView
顯示效果有多種:成功(默認(rèn))/錯(cuò)誤/警告/詳情/自定義圖標(biāo)
- 成功(默認(rèn))
成功
- 錯(cuò)誤
錯(cuò)誤
- 警告
警告
- 詳情
詳情提示
使用方法
*使用初始化方法
//默認(rèn)顯示
RAlertView.init(title: String, detailText: String, cancelTitle: String)
//如果修改顯示樣式
RAlertView.init(title: String, detailText: String, cancelTitle: String, style: RAlertStyle)
//如果需要完成后處理點(diǎn)事情
RAlertView.init(title: String, detailText: String, cancelTitle: String, style: RAlertStyle, completClosure: (()->())?)
//如果需要添加多個(gè)按鈕 需要設(shè)置delegate
RAlertView.init(title: String, detailText: String, cancelTitle: String, style: RAlertStyle, delegate: RAlertViewDelegate?, otherTitles: Array<String>?, completClosure: (() -> ())?)
- 顯示樣式
//彈窗樣式
enum RAlertStyle: Int {
case Success,Error,Warning,Info,Custom,Default;
}
- 設(shè)置滑入屏幕的模式
//滑入樣式
enum RAlertModel: Int{
case Fade,Top,Bottom,Left,Right;
}
alert.enterModel = .Left
alert.leavaModel = .Right
- 顯示
alert.show()
- 多個(gè)按鈕時(shí)實(shí)現(xiàn)代理方法
extension XXViewController: RAlertViewDelegate{
func alertView(alertView: RAlertView, didClickIndex: Int) {
print(didClickIndex)
}
}
封裝完這個(gè)彈窗用Instruments測(cè)試了下Demo發(fā)現(xiàn)有內(nèi)存泄漏問(wèn)題渗常,經(jīng)過(guò)研究添加了alertDestroy方式來(lái)完成彈窗的掃尾工作壮不。