Swift alert 倒计时
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 倒计时的更多相关文章
- Swift - UITableViewCell倒计时重用解决方案
Swift - UITableViewCell倒计时重用解决方案 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CountDo ...
- 纯js实现10分钟倒计时
一个简单实现倒计时的小栗子~ 效果图:简陋的不能再简陋了,捂脸 代码: <!DOCTYPE HTML> <html> <head> <title> 倒计 ...
- php和js一起实现倒计时功能
里获取的php服务端的时间 纯JS是获取客服端时间! <?php //php的时间是以秒算.js的时间以毫秒算 date_default_timezone_set('PRC'); //date_ ...
- js 倒计时 button不可用
function showtime() { fun_timedown(5); } function fun_timedown(time) { $("#timedown").val( ...
- new Date() 倒计时
js中单独调用new Date() 显示的结果是:Fri May 20 2015 20:00:00 GMT+0800这种格式的时间 JS获取当前时间戳的方法 JavaScript 获取当前时间戳: 第 ...
- jQuery倒计时组件(jquery.downCount.js)
//html <span class="days">00</span> <span class="hours">00< ...
- 毫秒倒计时小Demo
Demo截图: Demo:Demo 上代码: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- jquery实现倒计时
<html> <head> <meta charset="utf-8"/> <title>jquery实现倒计时</title ...
- JavaScript学习笔记之BOM对象
目录 1.Window 2.Window Screen 3.Window Location 4.Window History 5.Window Navigator 浏览器对象模型(Browser Ob ...
随机推荐
- shell 中小括号,中括号,大括号的区别
一.小括号,圆括号() 1.单小括号 () ①命令组.括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号隔开,最后一个命令可以没有分号, ...
- Docker容器间网络互联原理,讲不明白算我输....
@ 目录 一.今天我们要搞明白的实验 二.前置网络知识 2.1.docker默认为我们创建的网络 2.2.怎么理解docker0网桥 2.3.什么是veth-pair技术? 三.同一个局域网中不同主机 ...
- MySQL新建用户并赋予权限:解决命令行与Navicat展示数据库不一致问题
1.创建新用户 'xiaoxiao'密码'123456' mysql> CREATE USER 'xiaoxiao'@'localhost' IDENTIFIED BY '123456'; 2. ...
- pycharm 在flask断点不停止
For me disabling Gevent compatible option in Preferences > Build, Execution, Deployment has helpe ...
- Part 15 AngularJS ng init directive
The ng-init directive allows you to evaluate an expression in the current scope. In the following e ...
- 动手写一个简单的Web框架(HelloWorld的实现)
动手写一个简单的Web框架(HelloWorld的实现) 关于python的wsgi问题可以看这篇博客 我就不具体阐述了,简单来说,wsgi标准需要我们提供一个可以被调用的python程序,可以实函数 ...
- centos7.6自动化安装mysql5.5
一.目的 简化安装mysql的安装过程,局限很大,仅支持centos7.6上安装mysql5.5.60,如果想在其他版本的操作系统安装mysql,请自行修改有关变量. 如果想了解mysql安装的具体过 ...
- tomcat隐藏版本号
默认报错页面信息会暴露出版本号 进入tomcat的lib目录找到catalina.jar文件 unzip catalina.jar之后会多出两个文件夹 进入org/apache/catalina/ut ...
- [loj3364]植物比较
结论:设$b_{i}$满足该限制,则$a_{i}$合法当且仅当$\forall i\ne j,a_{i}\ne a_{j}$且$\forall |i-j|<k,[a_{i}<a_{j}]= ...
- python 内置模块续(二)
目录 python 内置模块补充 1.hashlib模块 简易使用: 高级使用: 进阶使用: 加盐处理: 校验文件一致性 2.logging日志模块 日志等级 常用处理 "四大天王" ...