加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift开发笔记11 - 使用UIAlertController在底部弹出日期选择框

发布时间:2020-12-14 01:46:08 所属栏目:百科 来源:网络整理
导读:点击日期按钮,弹出一个日期选择框在底部,选完日期后,修改日期按钮上的文字: 关于日期按钮的外观绘制详见上一节,点击按钮的响应事件为: @IBAction func selectDate(sender: AnyObject) { let alertController:UIAlertController=UIAlertController(titl

点击日期按钮,弹出一个日期选择框在底部,选完日期后,修改日期按钮上的文字:


关于日期按钮的外观绘制详见上一节,点击按钮的响应事件为:

 @IBAction func selectDate(sender: AnyObject) {
        
        let alertController:UIAlertController=UIAlertController(title: "nnnnnnnnnnnn",message: nil,preferredStyle: UIAlertControllerStyle.ActionSheet)
        // 初始化 datePicker
        let datePicker = UIDatePicker( )
        //将日期选择器区域设置为中文,则选择器日期显示为中文
        datePicker.locale = NSLocale(localeIdentifier: "zh_CN")
        // 设置样式,当前设为同时显示日期和时间
        datePicker.datePickerMode = UIDatePickerMode.Date
        // 设置默认时间
        datePicker.date = NSDate()
        // 响应事件(只要滚轮变化就会触发)
        // datePicker.addTarget(self,action:Selector("datePickerValueChange:"),forControlEvents: UIControlEvents.ValueChanged)
        alertController.addAction(UIAlertAction(title: "确定",style: UIAlertActionStyle.Default){
            (alertAction)->Void in
            print("date select: (datePicker.date.description)")
            //获取上一节中自定义的按钮外观DateButton类,设置DateButton类属性thedate
            let myDateButton=self.Datebutt as? DateButton
            myDateButton?.thedate=datePicker.date
            //强制刷新
            myDateButton?.setNeedsDisplay()
            })
        alertController.addAction(UIAlertAction(title: "取消",style: UIAlertActionStyle.Cancel,handler:nil))
        
        alertController.view.addSubview(datePicker)
        
        self.presentViewController(alertController,animated: true,completion: nil)
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读