論 Swift 開發入門 : 進度條(UIProgressView)

來源:互聯網
上載者:User

標籤:ios   swift   進度條   uiprogressview   

轉載請聲明出處:http://blog.csdn.net/jinnchang/article/details/44802019
------------------------------------------------------------------------------------------
概述
------------------------------------------------------------------------------------------
程式碼範例
import UIKitclass ViewController: UIViewController {        var button: UIButton!    var progressView: UIProgressView!        var timer: NSTimer!    var remainTime = 100        override func viewDidLoad() {        // 初始化按鈕,開始倒計時        button = UIButton.buttonWithType(.System) as UIButton        button.frame = CGRectMake(self.view.frame.width/2 - 50, 50, 100, 50)        button.setTitle("開始", forState: UIControlState.Normal)        button.addTarget(self, action: "buttonAction", forControlEvents: UIControlEvents.TouchUpInside)                // 初始化 progressView        progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Bar)        progressView.frame = CGRectMake(self.view.frame.width/2 - 50, 200, 100, 100)        // 設定初始值        progressView.progress = 1.0        // 設定進度條顏色        progressView.progressTintColor = UIColor.blueColor()        // 設定進度軌跡顏色        progressView.trackTintColor = UIColor.greenColor()        // 擴充:可以通過 progressImage、trackImage 屬性自訂出個性進度條                self.view.addSubview(button)        self.view.addSubview(progressView)    }        /// 響應按鈕點擊事件,開始倒計時    func buttonAction() {        button.enabled = false        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "timerAction", userInfo: nil, repeats:true)        timer.fire()    }        // 每秒定時觸發    func timerAction() {        if(remainTime < 0){            //倒計時結束            timer.invalidate()        } else {            println("\(remainTime)")            remainTime = remainTime - 1            let progressValue = Float(remainTime)/100            progressView.setProgress(progressValue, animated:true)        }    }    }
------------------------------------------------------------------------------------------
結語GitHub 上項目地址:UIProgressViewSample

文章最後更新時間:2015年4月1日09:08:34。參考資料如下:

UIProgressView Class Reference

UIKit User Interface Catalog: Progress Views

論 Swift 開發入門 : 進度條(UIProgressView)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.