Swift开发:UIAlertController 弹框

前端之家收集整理的这篇文章主要介绍了Swift开发:UIAlertController 弹框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

封装了一个函数,用于弹框


/**

弹框

- parameter title: 标题

- parameter msg: 消息

- parameter btns: 弹框项

*/

func show(title:String,msg:String,btns:[String]?) {

let alert = UIAlertController(title: title,message: msg,preferredStyle: .Alert);

for(var i=0;i<btns?.count;i++) {

let btn = UIAlertAction(title: btns![i],style: .Default) { (UIAlertAction) -> Void in

print(UIAlertAction.title); // 打印选中内容

}

alert.addAction(btn);

}

let btn = UIAlertAction(title: "取消",style:.Destructive) { (UIAlertAction) -> Void in

var choose = -1;

}

alert.addAction(btn);


self.presentViewController(alert,animated: true,completion: nil);

}


使用方法

let serialBar:[String] = [" ","串口号","波特率","数据位","停止位","校验位",""," ","校验位"];



let serialBarData:[Int:[String]] = [0:["Rs232"],

1:["1","2","3","4"],

2:["9600","19200","38400","115200"],

3:["8","9"],

4:["1","1.5","2"],

5:["奇校验","偶校验",27)">无校验"],

6:[""],

7:["Rs485"],

8:["1",

9:["9600",

10:["8",

11:["2","1"],

12:[" ];


上面是字典

show(serialBar[row],msg: "请选择数据",btns: serialBarData[row])


效果图: [如果只有2项,就横着排]



原文链接:https://www.f2er.com/swift/321912.html

猜你在找的Swift相关文章