聽說Swift5趨于穩(wěn)定了牙咏。湊空看了下Swift,寫了個(gè)簡單的demo:https://github.com/lihui1314/LHPromptBoxTool
效果圖如下:
做了簡單的封裝,代碼調(diào)用起來也很方便厂抽,如下:
@objc func btnAction(sender:UIButton) -> Void {
let prompt = LHPromptBoxView()
let mode1 = LHPromptModel()
mode1.name = "Apple"
let mode2 = LHPromptModel()
mode2.name = "Google"
let mode3 = LHPromptModel()
mode3.name = "Cancel"
mode3.color = UIColor.red
prompt.modelArray = [mode1,mode2,mode3]
prompt.lh_show()
prompt.delegate = self
//如果有閉包的實(shí)現(xiàn),會(huì)優(yōu)先執(zhí)行閉包,沒有閉包實(shí)現(xiàn)的話會(huì)下面的代理暗甥,二者選一即可
prompt.selectBlock = {(index:Int)->Void in
print(index)
}
}
//點(diǎn)擊代理方法
func lh_didSelet(index: Int) {
print(index)
}