zoukankan      html  css  js  c++  java
  • Swift

     

    1,创建进度条

    1
    2
    3
    4
    var progressView=UIProgressView(progressViewStyle:UIProgressViewStyle.Default)
    progressView.center=self.view.center
    progressView.progress=0.5 //默认进度50%
    self.view.addSubview(progressView);
     

    2,设置进度,同时有动画效果

    1
    progressView.setProgress(0.8,animated:true)
     

    3,改变进度条颜色

    1
    2
    progressView.progressTintColor=UIColor.greenColor()  //已有进度颜色
    progressView.trackTintColor=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
    27
    import UIKit
     
    class ViewControllerUIViewController {
        
        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
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    import UIKit
     
    class ViewControllerUIViewController {
        
        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)
             
            //通过变形改变进度条高度( 横向宽度不变,纵向高度变成默认的5倍)
            myProgressView.transform = CGAffineTransformMakeScale(1.0, 5.0)
             
            //进度条条进度
            myProgressView.progress = 0.3
             
            //把进度条添加到view中来
            self.view.addSubview(myProgressView)
        }
     
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }

     

  • 相关阅读:
    node之时间
    node之querystring
    学图像处理应该学Matlab还是C++
    柯西—施瓦茨不等式
    矿区 GPS 变形监测及其伪卫星增强技术 GPS and its Pseudolite Augmented Technique for Deformation Monitoring in the Mining Area
    伪卫星
    The Principles of Selection. The Cartographic Journal, 3, 10-16. http://dx.doi.org/10.1179/caj.1966.3.1.10 Topfer, F. and Pillewizer, W. (1966)
    基于采样的网络地图的多尺度曲线绘制表达
    Coursera上Python课程(公开课)汇总
    三江源区高寒草地地上生物量遥感反演模型研究 Modeling Aboveground Biomass of Alpine Grassland in the Three-River Headwaters Region Based on Remote Sensing Data
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10311554.html
Copyright © 2011-2022 走看看