• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请



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人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap