Swift UIAlterViewController

Swift UIAlterViewController,第1张

概述import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //定义按钮,显示最简单的Alter let button1 = UIButton(type: UIButtonType.Syst
import UIKitclass VIEwController: UIVIEwController {    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        //定义按钮,显示最简单的Alter        let button1 = UIbutton(type: UIbuttonType.System)        button1.frame = CGRectMake(30,70,self.vIEw.frame.size.wIDth-60,35)        button1.setTitle("最简单的Alter",forState: UIControlState.normal)        button1.addTarget(self,action: "button1Action:",forControlEvents: UIControlEvents.touchUpInsIDe)        self.vIEw .addSubvIEw(button1)        //定义按钮,显示带文本框的Alter        let button2 = UIbutton(type: UIbuttonType.System)        button2.frame = CGRectMake(30,125,35)        button2.setTitle("带文本框的Alter",forState: UIControlState.normal)        button2.addTarget(self,action: "button2Action:",forControlEvents: UIControlEvents.touchUpInsIDe)        self.vIEw.addSubvIEw(button2)        //定义按钮,显示上拉菜单        let button3 = UIbutton(type: UIbuttonType.System)        button3.frame = CGRectMake(30,180,35)        button3.setTitle("上拉菜单",forState: UIControlState.normal)        button3.addTarget(self,action: "button3Action:",forControlEvents: UIControlEvents.touchUpInsIDe)        self.vIEw.addSubvIEw(button3)    }    func button1Action(sender :UIbutton) {        let alterController = UIAlertController(Title: "最简单的Alter",message: nil,preferredStyle: UIAlertControllerStyle.Alert)        let action1 = UIAlertAction(Title: "星期一",style: UIAlertActionStyle.Default) { (UIAlertAction) -> VoID in        }        let action2 = UIAlertAction(Title: "星期二",style: UIAlertActionStyle.Destructive) { (UIAlertAction) -> VoID in        }        let action3 = UIAlertAction(Title: "星期三",style: UIAlertActionStyle.Default) { (UIAlertAction) -> VoID in        }        let action4 = UIAlertAction(Title: "取消",style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> VoID in        }        alterController.addAction(action1)        alterController.addAction(action2)        alterController.addAction(action3)        alterController.addAction(action4)        self .presentVIEwController(alterController,animated: true,completion: nil)    }    func button2Action(sender :UIbutton) {        let alterController = UIAlertController(Title: "带文本框的Alter",preferredStyle: UIAlertControllerStyle.Alert)        alterController.addTextFIElDWithConfigurationHandler { (textFIEld: UITextFIEld) -> VoID in            textFIEld.placeholder = "请输入账号"        }        alterController.addTextFIElDWithConfigurationHandler { (textFIEld: UITextFIEld) -> VoID in            textFIEld.placeholder = "请输入密码"            textFIEld.secureTextEntry = true        }        let action = UIAlertAction(Title: "登录",style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> VoID in        }        alterController.addAction(action)        self.presentVIEwController(alterController,animated: true) { () -> VoID in        }    }    func button3Action(sender: UIbutton) {        let alterController = UIAlertController(Title: "上拉菜单",preferredStyle: UIAlertControllerStyle.ActionSheet)        let action1 = UIAlertAction(Title: "星期一",completion: nil)    }}

DEMO下载

总结

以上是内存溢出为你收集整理的Swift UIAlterViewController全部内容,希望文章能够帮你解决Swift UIAlterViewController所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1077523.html

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

发表评论

登录后才能评论

评论列表(0条)

保存