大佬教程收集整理的这篇文章主要介绍了swift:iOS根据条件显示警报动作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
根据条件显示警报动作
var a = loggedInUsername if ((a?.range(of: "mother")) != nil) { print("true") print ("name:",loggedInUserName) let action1 = UIAlertAction(title: "delete",style: .default,handler: { (action) -> Void in print("ACTION 1 SELEcted!") }) let action2 = UIAlertAction(title: "Approve Chore",handler: { (action) -> Void in })
试试这个.
let alert = UIAlertController(title: AppName,message: "YOUR messaGE",preferredStyle: .alert) alert.view.TintColor = Colors.NavtitleColor let action1 = UIAlertAction(title: "delete",handler: {(_ action: UIAlertAction) -> Void in }) let action2 = UIAlertAction(title: "Approve Chore",style: .cancel,handler: {(_ action: UIAlertAction) -> Void in }) if ((a?.range(of: "mother")) != nil) { alert.addAction(action1) } else { alert.addAction(action2) } present(alert,animated: truE) {() -> Void in }
如果你想在UIAlertAction标题之前添加Image而不是使用下面的代码.
let alert = UIAlertController(title: "title",preferredStyle: .alert) alert.view.TintColor = Colors.NavtitleColor let image1 = UIImage(named: "attendance") let action1 = UIAlertAction(title: "delete",handler: nil) action1.SETVALue(image1,forKey: "image") let image2 = UIImage(named: "mail") let action2 = UIAlertAction(title: "Approve Chore",handler: nil) action2.SETVALue(image2,forKey: "image") alert.addAction(action1) alert.addAction(action2) present(alert,animated: truE) {() -> Void in }
看起来像下图.
@L_801_12@
以上是大佬教程为你收集整理的swift:iOS根据条件显示警报动作全部内容,希望文章能够帮你解决swift:iOS根据条件显示警报动作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。