ios swift 实现饼状图进度条,swift环形进度条

标签: iosswift
2467人阅读 评论(0) 收藏 举报
分类:



ios swift 实现饼状图进度条


//
//  ProgressControl.swift
//  L02MyProgressControl
//
//  Created by plter on 7/29/14.
//  Copyright (c) 2014 jikexueyuan. All rights reserved.
//

import UIKit

class ProgressControl: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
        
        self.backgroundColor = UIColor(white: 1, alpha: 0)
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    private var _progressValue:CGFloat = 0

    public func getProgressValue()->CGFloat{
        return _progressValue
    }
    
    public func setProgressValue(value:CGFloat){
        _progressValue = value
        
        setNeedsDisplay()
    }
    
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect)
    {
        // Drawing code
        
        var ctx = UIGraphicsGetCurrentContext()
        
        var r = rect.width/2
        
        CGContextAddArc(ctx, r, r, r, 0, 3.141592653*2, 0)
        CGContextSetRGBFillColor(ctx, 0.7, 0.7, 0.7, 1)
        CGContextFillPath(ctx)
        
        
        CGContextAddArc(ctx, r, r, r, 0, 3.141592653*2*_progressValue, 0)
        CGContextAddLineToPoint(ctx, r, r)
        CGContextSetRGBFillColor(ctx, 0, 0, 1, 1)
        CGContextFillPath(ctx)
    }

}



viewcontroller:

//
//  ViewController.swift
//  L02MyProgressControl
//
//  Created by plter on 7/29/14.
//  Copyright (c) 2014 jikexueyuan. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
                            
    @IBAction func addProgressBtnPressed(sender: AnyObject) {
        
        pc.setProgressValue(pc.getProgressValue()+0.1)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        pc = ProgressControl(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        self.view.addSubview(pc)
    }
    
    
    private var pc:ProgressControl!
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}




使用alertview展示的方案:


            let frame = CGRectMake(0, 0, 78, 78)
            let window = UIWindow()
            window.backgroundColor = UIColor.clearColor()
            let mainView = UIView()
            mainView.layer.cornerRadius = 12
            mainView.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.8)
            
            let ai = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
            ai.frame = CGRectMake(21, 21, 36, 36)
            ai.startAnimating()
            mainView.addSubview(ai)
            
            window.frame = frame
            mainView.frame = frame
           
            window.windowLevel = UIWindowLevelAlert
            window.center = self.view.center
            window.hidden = false
            window.addSubview(mainView)

一般的实现方法:


  //  activityIndicatorView
            
            m_objActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
            m_objActivityIndicatorView!.frame = CGRectMake(self.view.frame.size.width/2 - 100, self.view.frame.size.height/2 - 100, 200, 200)
            m_objActivityIndicatorView!.hidesWhenStopped = true
            m_objActivityIndicatorView!.color = UIColor.blackColor()
            m_objActivityIndicatorView!.layer.cornerRadius = 6
            m_objActivityIndicatorView!.layer.masksToBounds = true
            
            self.view.addSubview(m_objActivityIndicatorView)


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    公众号,github
    公众号:     老王和他的IT界朋友们
    欢迎投稿:  shiter@live.cn
    QQ交流群:  593683975
    加群问题:抛硬币正面上的期望?

    我们想用一段音乐,几张图片,
    些许文字绘制的IT圈心路历程,
    为攻城狮,为程序员带来更多的人文关怀。

    投稿原创文章有稿费,杂志等福利!!!



    github:  https://github.com/wynshiter
    个人资料
    • 访问:1209098次
    • 积分:13557
    • 等级:
    • 排名:第1077名
    • 原创:187篇
    • 转载:51篇
    • 译文:73篇
    • 评论:696条
    博客专栏
    百度统计
    微信公众号
      微信公众号
      老王和他的IT界朋友们