reprint Please declare source: http://blog.csdn.net/jinnchang/article/details/44802019
------------------------------------------------------------------------------------------
Overview
------------------------------------------------------------------------------------------
code Example
Import Uikitclass Viewcontroller:uiviewcontroller {var button:uibutton! var progressview:uiprogressview! var timer:nstimer! var remaintime = viewdidload func () {//Initialize button, start the countdown button = Uibutton.buttonwithtype (. S ystem) as UIButton button.frame = CGRectMake (SELF.VIEW.FRAME.WIDTH/2-A, +, +) Button.settitle ("Start" , ForState:UIControlState.Normal) Button.addtarget (Self, Action: "Buttonaction", forcontrolevents:uicontrolevents . Touchupinside)//Initialize Progressview Progressview = Uiprogressview (Progressviewstyle:uiprogressviewst Yle. Bar) Progressview.frame = CGRectMake (SELF.VIEW.FRAME.WIDTH/2-50, 200, 100, 100)//Set initial value PROGRESSVI Ew.progress = 1.0//Set progress bar Color Progressview.progresstintcolor = Uicolor.bluecolor ()//Set Progress track color Progressview.tracktintcolor = Uicolor.greencolor ()//EXTENSION: You can customize the progress bar by Progressimage, Trackimage properties Self.view.addSubview (Button) Self.view.addSubview (Progressview)}///Response button click event, start Countdown func Butto Naction () {button.enabled = False timer = Nstimer.scheduledtimerwithtimeinterval (1, target:self, selector: "Timeraction", Userinfo:nil, Repeats:true) Timer.fire ()}//per second timing trigger Func timeraction () {if (R Emaintime < 0) {//Countdown end Timer.invalidate ()} else {println ("\ (remaintime)") Remaintime = remainTime-1 Let Progressvalue = Float (remaintime)/100 progressview.setprogr ESS (Progressvalue, Animated:true)}}}
------------------------------------------------------------------------------------------
ConclusionProject on GitHub address: uiprogressviewsample
Article last updated: April 1, 2015 09:08:34. The resources are as follows:
Uiprogressview Class Reference
UIKit User Interface catalog:progress views
Introduction to Swift Development: progress bar (Uiprogressview)