Swift - 告警提示框(UIAlertController)的用法

Swift - 告警提示框(UIAlertController)的用法,第1张

概述自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView。下面总结了一些常见的用法: 1,简单的应用(同时按钮响应Handler使用闭包函数)    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import  UIKit   class  ViewCon 自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertVIEw。下面总结了一些常见的用法:
1,简单的应用(同时按钮响应Handler使用闭包函数)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import UIKit class VIEwController : UIVIEwController , UIActionSheetDelegate { overrIDe func vIEwDIDLoad() { super .vIEwDIDLoad() } vIEwDIDAppear(animated: Bool ){ .vIEwDIDAppear(animated) let alertController = UIAlertController (Title: "系统提示" "您确定要离开hangge.com吗?" UIAlertControllerStyle . Alert ) cancelAction = UIAlertAction "取消" UIAlertActionStyle Cancel nil ) okAction = "好的" Default in print ( "点击了确定" ) }) alertController.addAction(cancelAction) alertController.addAction(okAction) self .presentVIEwController(alertController,animated: true ) } dIDReceiveMemoryWarning() { .dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. } }

替代的UIAlert

//dialog 提示框

// let alert = UIAlertVIEw()

// alert.Title = "Refresh?"

// alert.message = "All data will be selected."

// alert.addbuttonWithTitle("Cancel")

// alert.addbuttonWithTitle("OK")

// alert.show()

2,除了d出,还可以使用从底部向上滑出的样式
(注意:如果上拉菜单中有“取消”按钮的话,那么它永远都会出现在菜单的底部,不管添加的次序是如何) 1 2 9
var alertController = UIAlertController "保存或删除数据" "删除数据将不可恢复" preferredStyle: UIAlertControllerStyle ActionSheet ) cancelAction = UIAlertAction ) deleteAction = "删除" UIAlertActionStyle Destructive ) archiveAction = "保存" ) alertController.addAction(cancelAction) alertController.addAction(deleteAction) alertController.addAction(archiveAction) )

3,按钮使用“告警”样式(文字颜色变红,用来来警示用户) 1
4,添加任意数量文本输入框(比如可以用来实现个登陆框) 12 13 14 @H_588_403@ 15 16 17 18 19 20 21 25 @H_279_419@ 26 27 28 29 30 31 32 33 34 35 36 37 38
import UIKit UIActionSheetDelegate vIEwDIDAppear(animated: Bool "系统登录" "请输入用户名和密码" ) alertController.addTextFIElDWithConfigurationHandler { (textFIEld: UITextFIEld !) -> VoID in textFIEld.placeholder = "用户名" } alertController.addTextFIElDWithConfigurationHandler { in "密码" textFIEld.secureTextEntry = true } ) okAction = as UITextFIEld password = alertController.textFIElds!.last! as UITextFIEld "用户名:\(login.text) 密码:\(password.text)" ) }) alertController.addAction(cancelAction) alertController.addAction(okAction) ) } dIDReceiveMemoryWarning() { .dIDReceiveMemoryWarning() } }

5,使用代码移除提示
.presentedVIEwController?.dismissVIEwControllerAnimated(false 原文出自: www.hangge.com 转载请保留原文链接: http://www.hangge.com/blog/cache/detail_651.html 总结

以上是内存溢出为你收集整理的Swift - 告警提示框(UIAlertController)的用法全部内容,希望文章能够帮你解决Swift - 告警提示框(UIAlertController)的用法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1091034.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)