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




    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,  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)
    


  • 相关阅读:
    SQL优化——union与union all 、left join 和 inner join 及 内连接
    用jdk自带工具jvisualvm查看系统内存使用情况
    不重启也能清理catalina.out日志的方法
    自己用crontab弄个定时任务备份日志重启项目
    三层架构的一点理解以及Dapper一对多查询
    Nuget包添加文件
    WPF启动流程-自己手写Main函数
    WPF实现手势解锁
    VS提交码云权限问题
    Json转Dictionary
  • 原文地址:https://www.cnblogs.com/wangyaning/p/7853950.html
Copyright © 2020-2023  润新知