UIAlertView/UIActionSheet

UIAlertView

     //一个按钮的提醒
     @IBAction func oneButtonAler()
     {
         //创建单一按钮提醒视图
         let oneButtonAlert:UIAlertView = UIAlertView(title: "提醒", message: "这是一个简单的提醒视图", delegate: nil, cancelButtonTitle: "确定")
         //显示提醒视图
         oneButtonAlert.show()

         //设置提醒视图样式
         oneButtonAlert.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput

         //来获取提醒视图上的文本框
         var textField : UITextField? = oneButtonAlert.textFieldAtIndex()

         //设置文本框占位符
         textField?.placeholder = "请输入账号"

     }

     //多个按钮的提醒
     @IBAction func moreButtonAler()
     {

         //创建多按钮提醒视图
         let moreButtonAlert:UIAlertView = UIAlertView(title: "提醒", message: "多按钮提醒钮视图,请选择一个按钮", delegate: self, cancelButtonTitle: "确定" , otherButtonTitles: "按钮 1","按钮 2","按钮 3","按钮 4")
         //显示图像视图
         moreButtonAlert.show()

         //设置代理
         moreButtonAlert.delegate = self

 //        //方法二
 //        //初始化空得alert
 //        let alert = UIAlertView()
 //        //设置标题
 //        alert.title = "提醒"
 //        //设置代理
 //        alert.delegate = self
 //        //设置提醒信息
 //        alert.message = "多按钮提醒钮视图,请选择一个按钮"
 //
 //        //添加按钮,可以添加多个
 //        alert.addButtonWithTitle("按钮 1")
 //        alert.addButtonWithTitle("按钮 2")
 //        alert.addButtonWithTitle("按钮 3")
 //        alert.addButtonWithTitle("按钮 4")
 //
 //        //显示
 //        alert.show()
     }

     override func viewDidLoad() {
         super.viewDidLoad()

         titleLabel.text = titleString

         // Do any additional setup after loading the view.
     }

     override func didReceiveMemoryWarning() {
         super.didReceiveMemoryWarning()
         // Dispose of any resources that can be recreated.

     }

     /*
     // MARK: - Navigation

     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
         // Get the new view controller using segue.destinationViewController.
         // Pass the selected object to the new view controller.
     }
     */

     // MARK: - UIAlertViewDelegate

     //根据被点击按钮的索引处理点击事件
     func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)
     {
         switch buttonIndex
         {
             :
                 println("按钮 1")
             :
                 println("按钮 2")
             :
                 println("按钮 3")
             :
                 println("按钮 4")
             default:
                 println("点击确定")
         }
     }

     //取消按钮的事件
     func alertViewCancel(alertView: UIAlertView)
     {

     }

     //即将显示时
     func willPresentAlertView(alertView: UIAlertView)
     {

     }

     //已经显示时的事件
     func didPresentAlertView(alertView: UIAlertView)
     {

     }

     //即将消失时的事件
     func alertView(alertView: UIAlertView, willDismissWithButtonIndex buttonIndex: Int)
     {

     }

     //已经消失时的事件
     func alertView(alertView: UIAlertView, didDismissWithButtonIndex buttonIndex: Int)
     {

     }

     //编辑任何默认的字段添加的风格之后调用
     func alertViewShouldEnableFirstOtherButton(alertView: UIAlertView) -> Bool
     {
         return false
     }

UIActionSheet

     @IBAction func showActionSheet1()
     {
         //创建不带红色按钮的操作表
         var actionSheet:UIActionSheet = UIActionSheet(title: "请选择分享方向", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "邮件", "短信","微博","微信")

         actionSheet.delegate = self

         //显示到self.view视图上
         actionSheet.showInView(self.view)

         //设置标题
         actionSheet.title = "新标题"

         //设置样式
         actionSheet.actionSheetStyle = UIActionSheetStyle.BlackTranslucent

         //添加按钮
         actionSheet.addButtonWithTitle("新加按钮")

         //根据index坐标获取一个按钮的文本
         var butIndex = actionSheet.buttonTitleAtIndex()

         //获取取消按钮的坐标
         var cancelIndex = actionSheet.cancelButtonIndex

         //获取按钮个数
         var butCount = actionSheet.numberOfButtons

     }

     @IBAction func showActionSheet2()
     {

         //创建带有红色按钮的操作表
         var actionSheet2:UIActionSheet = UIActionSheet(title: "将删除该条评论", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "确定删除")

         //显示到self.view视图上
         actionSheet2.showInView(self.view)
     }

     override func viewDidLoad() {
         super.viewDidLoad()

         titleLabel.text = titleString

         // Do any additional setup after loading the view.
     }

     override func didReceiveMemoryWarning() {
         super.didReceiveMemoryWarning()
         // Dispose of any resources that can be recreated.
     }

     /*
     // MARK: - Navigation

     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
         // Get the new view controller using segue.destinationViewController.
         // Pass the selected object to the new view controller.
     }
     */

     // MARK: - UIActionSheetDelegate

     //根据被点击按钮的索引处理点击事件
     func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)
     {
         switch buttonIndex
             {
         :
             println("点击取消")
         :
             println(")
         :
             println(")
         :
             println(")
         default:
             println("未知")
         }
     }

     //选择取消按钮
     func actionSheetCancel(actionSheet: UIActionSheet)
     {

     }

     //即将显示时
     func willPresentActionSheet(actionSheet: UIActionSheet)
     {

     }

     //已显示时
     func didPresentActionSheet(actionSheet: UIActionSheet)
     {

     }

     //即将消失
     func actionSheet(actionSheet: UIActionSheet, willDismissWithButtonIndex buttonIndex: Int)
     {

     }

     //已消失
     func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int)
     {

     }
 
 

iOS开发——UI篇Swift篇&UIAlertView/UIActionSheet的更多相关文章

  1. iOS开发——技术精华Swift篇&Swift 2.0和Objective-C2.0混编之第三方框架的使用

    swift 语言是苹果公司在2014年的WWDC大会上发布的全新的编程语言.Swift语言继承了C语言以及Objective-C的特性,且克服了C语言的兼容性问题.Swift语言采用安全编程模式,且引 ...

  2. iOS开发——新特性Swift篇&Swift 2.0 异常处理

    Swift 2.0 异常处理 WWDC 2015 宣布了新的 Swift 2.0. 这次重大更新给 Swift 提供了新的异常处理方法.这篇文章会主要围绕这个方面进行讨论. 如何建造异常类型? 在 i ...

  3. iOS开发——UI精选OC篇&UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍

    UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍 一:UIApplication:单例(关于单例后面的文章中会详细介绍,你现在只要知道 ...

  4. iOS开发——网络编程Swift篇&Alamofire详解

    Alamofire详解 预览图 Swift Alamofire 简介 Alamofire是 Swift 语言的 HTTP 网络开发工具包,相当于Swift实现AFNetworking版本. 当然,AF ...

  5. ios开发——实用技术篇Swift篇&地址薄、短信、邮件

    //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...

  6. ios开发——实用技术总结Swift篇&swift常用开发技术总结

    swift常用开发技术总结 懒加载:属性,数组(字典),控件... 数组(懒加载): lazy var shops:Array<Dictionary<String, String>& ...

  7. ios开发——实用技术篇Swift篇&拍照

    拍照 // MARK: - 拍照 func fromPhotograph() { if UIImagePickerController.isSourceTypeAvailable(.Camera) { ...

  8. ios开发——实用技术篇Swift篇&照片选择

    照片选择 // MARK: - 选择照片 /*----- 选择照片 ------*/ @IBAction func addImageButtonClick() { let actionSheet = ...

  9. iOS开发——网络编程Swift篇&(八)SwiftyJSON详解

    SwiftyJSON详解 最近看了一些网络请求的例子,发现Swift在解析JSON数据时特别别扭,总是要写一大堆的downcast(as?)和可选(Optional),看?号都看花了.随后发现了这个库 ...

  10. ios开发——实用技术篇Swift篇&加速计和陀螺仪

    加速计和陀螺仪 //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnim ...

随机推荐

  1. How To Set Up Port Forwarding in Linux

    Port forwarding usually used when we want our computer act like a router. Our computer receive the p ...

  2. Linux下的GitHub安装与简单配置教程

    1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与使用 在ubuntu下可以使用如下命令进行查看系统 ...

  3. 使用VMware10虚拟机安装Linux系统(能力工场)

    作为IT从业人员,我们经常使用到Linux系统,但是实际开发过程我们通常在Windows平台操作,为了满足工作需要,这个时候我们通常在windows平台安装虚拟机,并在其上建立linux系统,这样就极 ...

  4. 非对称认证方式 可以用在 asp.net webapi 的安全机制里面

    //Client端调用 static void Main(string[] args) { string publicKey = "DpLMCOihcYI2i6DaMbso9Dzo1miy7 ...

  5. Jquery 等待ajax返回数据loading控件ShowLoading组件

    1.意义 开发项目中,前台的页面要发请求到服务器,服务器响应请求返回数据到前台,这段时间,有可能因为返回的数据量较大导致前台页面出现短暂性的等待,此时如果用户因不知情而乱点击有可能造成逻辑混乱,所以此 ...

  6. Delphi IOS环境安装

    RAD Delphi XE/10 Seattle 安装IOS.OSX环境安装,IOS模拟器,MAC X 真机可以调试 http://community.embarcadero.com/blogs/en ...

  7. 转】用Maven构建Mahout项目

    原博文出自于: http://blog.fens.me/hadoop-mahout-maven-eclipse/ 感谢! 用Maven构建Mahout项目 Hadoop家族系列文章,主要介绍Hadoo ...

  8. Spark RDD概念学习系列之RDD的checkpoint(九)

     RDD的检查点 首先,要清楚.为什么spark要引入检查点机制?引入RDD的检查点?  答:如果缓存丢失了,则需要重新计算.如果计算特别复杂或者计算耗时特别多,那么缓存丢失对于整个Job的影响是不容 ...

  9. HD2025查找最大元素

    查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  10. Windows PE3.0制作方法(从Win7中提取制作)

    Windows PE3.0制作方法(从Win7中提取制作 在d:新建文件夹winpe,在winpe中新建sources.pe3和new文件夹,把附件中提供的工具imagex连文件夹一起放到winpe目 ...