Swift-进度条(UIProgressView)的⽤法1,创建进度条
1 2 3 4var progressView=UIProgressView(progressViewStyle:UIProgressViewStyle.Default) =
progressView.progress=0.5 //默认进度50%
self.view.addSubview(progressView);
2,设置进度,同时有动画效果
1progressView.setProgress(0.8,animated:true) 3,改变进度条颜⾊
1 2progressView.Color()  //已有进度颜⾊ackTintColor=UIColor.blueColor()  //剩余进度颜⾊(即进度槽颜⾊)
4,设置progressView的宽度(进度条长度)
通常情况下,我们可以在初始化 progressView 的时候通过 frame 属性设置其宽度(进度条长度)。⽐如下⾯样例,我在屏幕中放置⼀个横向宽度是200的进度条,其位置是⽔平居中。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27import UIKit
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//将背景设为⿊⾊
self.view.backgroundColor = UIColor.blackColor()
//创建⼀个宽度是200的进度条
let myProgressView = UIProgressView(frame: CGRectMake(0, 0, 200, 10))        //设置进度条位置(⽔平居中)
myProgressView.layer.position = CGPoint(x: self.view.frame.width/2, y: 100)        //进度条条进度
myProgressView.progress = 0.3
//把进度条添加到view中来
self.view.addSubview(myProgressView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
2,设置progressView的⾼度
但我们会发现⽆论如何设置 progressView 的⾼度,其最终显⽰出来的⾼度都不会变化。所以如果想改变⾼度,可以换个思路,通过改变 progressView 的 scale(缩放⽐例)来实现。
下⾯样例将进度条⾼度调整到默认的5倍。
1
2 3 4 5 6 7 8 9import UIKit
view ui框架class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//将背景设为⿊⾊
self.view.backgroundColor = UIColor.blackColor()
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30        self.view.backgroundColor = UIColor.blackColor()
//创建⼀个宽度是200的进度条
let myProgressView = UIProgressView(frame: CGRectMake(0, 0, 200, 10))        //设置进度条位置(⽔平居中)
myProgressView.layer.position = CGPoint(x: self.view.frame.width/2, y: 100)        //通过变形改变进度条
⾼度(横向宽度不变,纵向⾼度变成默认的5倍)
//进度条条进度
myProgressView.progress = 0.3
//把进度条添加到view中来
self.view.addSubview(myProgressView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}