首页 技术 正文
技术 2022年11月15日
0 收藏 693 点赞 3,918 浏览 1732 个字
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()
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290