let title: String = "您的开奖时间为"
let time: String = "2017-10-23 12:23:18"
let count_down: NSString = "6" as NSString
var countdown = count_down.integerValue
let timeout: String = "开奖时间已超时,请重新获取"
let alertVc = UIAlertController.init(title: nil, message: title + "\n" + time, preferredStyle: UIAlertControllerStyle.alert)
let alertAction0 = UIAlertAction.init(title: "取消", style: .default, handler: { (action) in })
let alertAction1 = UIAlertAction.init(title: "确定(\(countdown))", style: .default, handler: { (action) in
//确定的操作
})
alertVc.addAction(alertAction1)
alertVc.addAction(alertAction0)
weakSelf?.present(alertVc, animated: true, completion: {
})
if countdown != 0 {
let queue: DispatchQueue = DispatchQueue.global()
let countdownTimer = DispatchSource.makeTimerSource(flags: [], queue: queue)
countdown = countdown + 1
countdownTimer.scheduleRepeating(deadline: .now(), interval: .seconds(1))
countdownTimer.setEventHandler(handler: {
countdown = countdown - 1
if countdown <= 0 {
countdownTimer.cancel()
DispatchQueue.main.async {
alertAction1.setValue("确定(0)", forKey: "title")
alertAction1.setValue(UIColor.hrgb("CCCCCC"), forKey: "titleTextColor")
alertAction1.isEnabled = false
// message
let one: NSString = "\(title)\n\(time)\n" as NSString
let two: NSString = "\(timeout)" as NSString
let message = "\(title)\n\(time)\n\(timeout)"
let alertControllerMessageStr = NSMutableAttributedString(string: message)
alertControllerMessageStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.hrgb("DF503C"), range: NSMakeRange(one.length, two.length))
alertControllerMessageStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 13), range: NSMakeRange(one.length, two.length))
alertVc.setValue(alertControllerMessageStr, forKey: "attributedMessage")
}
}else {
DispatchQueue.main.async {
alertAction1.setValue("确定(\(countdown))", forKey: "title")
}
}
})
countdownTimer.resume()
}

Swift alert 倒计时的更多相关文章

  1. Swift - UITableViewCell倒计时重用解决方案

    Swift - UITableViewCell倒计时重用解决方案 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CountDo ...

  2. 纯js实现10分钟倒计时

    一个简单实现倒计时的小栗子~ 效果图:简陋的不能再简陋了,捂脸 代码: <!DOCTYPE HTML> <html> <head> <title> 倒计 ...

  3. php和js一起实现倒计时功能

    里获取的php服务端的时间 纯JS是获取客服端时间! <?php //php的时间是以秒算.js的时间以毫秒算 date_default_timezone_set('PRC'); //date_ ...

  4. js 倒计时 button不可用

    function showtime() { fun_timedown(5); } function fun_timedown(time) { $("#timedown").val( ...

  5. new Date() 倒计时

    js中单独调用new Date() 显示的结果是:Fri May 20 2015 20:00:00 GMT+0800这种格式的时间 JS获取当前时间戳的方法 JavaScript 获取当前时间戳: 第 ...

  6. jQuery倒计时组件(jquery.downCount.js)

    //html <span class="days">00</span> <span class="hours">00< ...

  7. 毫秒倒计时小Demo

    Demo截图: Demo:Demo 上代码: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  8. jquery实现倒计时

    <html> <head> <meta charset="utf-8"/> <title>jquery实现倒计时</title ...

  9. JavaScript学习笔记之BOM对象

    目录 1.Window 2.Window Screen 3.Window Location 4.Window History 5.Window Navigator 浏览器对象模型(Browser Ob ...

随机推荐

  1. elasticsearch7.x配置文件

    前言: 以下配置文件基于elasticsearch-7.13.4版本,当然也适用于其它7.x版本 集群环境: 部署3个节点的集群,各个节点不做角色区分,既是master,也是data,在性能 上这种方 ...

  2. idea中的maven模块变成灰色

    问题 在使用idea的过程中,遇到其中一个maven模块变成灰色,如下所示: 解决方法 方法一 造成这个的原因可能是忽略了maven模块,可以尝试如下解决方法:在idea中maven中找到ignore ...

  3. 手把手教你学Dapr - 5. 状态管理

    上一篇:手把手教你学Dapr - 4. 服务调用 介绍 使用状态管理,您的应用程序可以将数据作为键/值对存储在支持的状态存储中. 您的应用程序可以使用 Dapr 的状态管理 API 使用状态存储组件来 ...

  4. Spring Boot 面试总结

    1.使用 Spring Boot 前景? 多年来,随着新功能的增加,spring变得越来越复杂.只需访问https://spring.io/projects页面,我们就会看到可以在我们的应用程序中使用 ...

  5. js 增删节点

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  6. 13-Semi-supervised Learning

    半监督学习(semi-supervised learning) 1.introduction 2.Semi-supervised Learning for Generative Model 3.Low ...

  7. 使用json.net实现复杂对象转换为QueryString

    目标:生成复杂对象的QueryString,比如 new { Field1 = 1, Field2 = new { Field3 = "2", Field4 = new[] { n ...

  8. [luogu5564]Say Goodbye

    两树相同的定义与题中相同,并定义两树完全相同当且仅当在不允许基环旋转的条件下相同 枚举基环的长度$l$,根据置换群的理论,答案即$\frac{1}{l}\sum_{i=1}^{l}f(i)$(其中$f ...

  9. 联盛德 HLK-W806 (五): W801开发板上手报告

    目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...

  10. Web Api 宿主的搭建

    首先我们要清楚一个概念,宿主.宿主是什么意思?先从了解一下Hosting开始吧! 有关Hosting的基础知识 Hosting是一个非常重要,但又很难翻译成中文的概念.翻译成:寄宿,大概能勉强地传达它 ...