zoukankan      html  css  js  c++  java
  • 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 + "
    " + 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)
    (time)
    " as NSString
                    let two: NSString = "(timeout)" as NSString
                    let message = "(title)
    (time)
    (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()
    }

     

  • 相关阅读:
    使用开源GIS克隆一个Google Map
    《3s新闻周刊》No.4:与国产GIS企业一起成长
    Google发布免费的SketchUp
    VB和VBA工程的一些限制
    推荐一个新的RSS阅读站点:抓虾
    USGS如何利用Google Earth
    ESRI今年的Dev Summit的幻灯片
    Google Map创建工具和资源
    《3s新闻周刊》第6期发布,本期话题:海外聚焦――空间信息技术进行式
    《Excel与VBA程序设计》最新进度(>75%)
  • 原文地址:https://www.cnblogs.com/HMJ-29/p/7723428.html
Copyright © 2011-2022 走看看