1,创建一个alertview,并带有“确定”和“取消”两个按钮

(注:在这里使用alertview,会报警告,那是因为从ios 8 以后,建议使用UIAlertviewController)

//警告框的用法
let alertView = UIAlertView()
alertView.title = "系统提示"
alertView.message = "您确定要离开吗"
alertView.addButton(withTitle: "取消")
alertView.addButton(withTitle: "确定")
alertView.cancelButtonIndex =
alertView.delegate = self
alertView.show()

代理方法的实现:

func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
        if buttonIndex == alertView.cancelButtonIndex {
            print("用户点击了取消")
        }else
        {
            print("用户点击了确定")
        }
    }

2,警告框的样式,一共有4种

`default`:默认样式
plainTextInput:带输入框的告警框
secureTextInput:带密码框的告警框
loginAndPasswordInput:带输入框和密码框的告警
//警告框的用法
let alertView = UIAlertView()
alertView.title = "系统提示"
alertView.message = "您确定要离开吗"
alertView.addButtonWithTitle("取消")
alertView.addButtonWithTitle("确定")
alertView.cancelButtonIndex =
alertView.delegate = self;
alertView.alertViewStyle = .loginAndPasswordInput //样式可以在这里设置
        alertView.show()

    func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
        if buttonIndex == alertView.cancelButtonIndex {
            print("用户点击了取消")
        }else
        {
            print("用户点击了确定")
            let name = alertView.textField(at: 0)
            let passWord = alertView.textField(at: 1)
            print("用户名是:\(String(describing: name))密码是:\(String(describing: passWord))")
            
            
        }
    }

下面是一个使用输入框和密码框的警告框样式:

swift - UIAlertView 的用法的更多相关文章

  1. Swift - enumerateObjectsUsingBlock的用法

    enumerateobjectsusingblock:不是Array的方法在NSArray使用.如果你想使用它,你需要一个实例NSArray而不是Array. import Foundation va ...

  2. swift函数的用法,及其嵌套实例

    import Foundation //swift函数的使用 func sayHello(name userName:String ,age:Int)->String{ return " ...

  3. Swift继承的用法

    一个类可以继承另一个类的方法,属性和其它特性.当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类).在Swift中,继承是区分「类」与其它类型的一个基本特征. 在Swift中,类可以调用和访问超 ...

  4. swift - UIAlertController 的用法

    ios 8 以后苹果官方建议使用UIAlertController这个类,所以专门去网上找资料,了解了下用法, 1.创建一个alertController let alertController = ...

  5. swift - UISlider 的用法

    swift的UISlider的用法和oc基本没有区别 1.创建 class SecondViewController: UIViewController { var slider = UISlider ...

  6. swift - UISegmentedControl 的用法

    一.创建控件,并监听控件选择值 /*选项除了文字还可以是图片 as关键字的作用就是字面意思:类型转换*/ let items = ["选项一", "选项二", ...

  7. swift UILable的用法

  8. Swift - UITableView的用法

    因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...

  9. swift - UIToolbar 的用法

    代码如下: 1.声明及初始化 var toolsBar = UIToolbar() toolsBar.frame = CGRect(x:, y:, width:SCREEN_WIDTH, height ...

随机推荐

  1. 【Java】初始化过程

    以下程序执行的结果是: class X{ Y y=new Y(); public X(){ System.out.print("X"); } } class Y{ public Y ...

  2. xcode常见报错调试

    转载来自于:http://www.cnblogs.com/g-ios/p/4625912.html(广_ios博客园) BMKGeoCodeSearch 反向地理编码一直失败 Location 申请的 ...

  3. 4款基于jquery的列表图标动画切换特效

    网页中列表图标随处可见,特别是移动网页上,基本上的导航都采用了列表图标.今天给大家分享4款基于juqery的列表图标和关闭图标的动画切换特效.喜欢的网友赶紧收藏吧. 在线预览   源码下载 实现的代码 ...

  4. Clipboard获取内容C#

    一.获取文本  textBox1.Text = Clipboard.GetData("Text").ToString(); 二.获取图像             pictureBo ...

  5. 解决 Plugin with id 'com.github.dcendents.android-maven' not found.

    在Android studio中引用第三方库的时候,报这个错. Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not ...

  6. Java:单例模式的七种写法<转>

    第一种(懒汉,线程不安全):  1 public class Singleton {   2     private static Singleton instance;   3     privat ...

  7. 网络硬盘录像机和数字硬盘录像机区别(nvr dvr ipc区别)

    DVR Digital Video Recorder 数字硬盘录像机   NVR  Network Video Recorder  网络硬盘录像机 DVR(数字硬盘录像机)和NVR(网络硬盘录像机)在 ...

  8. BeamNG.drive物理引擎评鉴

    BeamNG.drive是一款由BeamNG公司开发并于2013年首次发布的软体物理模拟游戏.作为模拟游戏,特别是物理模拟的粉丝,我早早就开始使用BeamNG.drive.我立即对崩溃的准确性和细节印 ...

  9. tp-03 模板显示

    方式模板:$this->display(); 每当建立一个控制器  都要在view建立一个名字相对应的文件夹   在建立相对于的页面.

  10. pyqt的setObjectName()/findChild()

    根据设置的Name标示查找组件的对象,关键函数:setObjectName()/findChild() findChild()/2:需要两个参数, 参数一:组件的类型,如QLineEdit.QPush ...