本篇文章主要介绍了"ios swift 实现饼状图进度条",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下:
ios swift 实现饼状图进度条//
// ProgressControl.swift
// L02MyProgressControl
//
// C...
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.
}
}
以上就介绍了ios swift 实现饼状图进度条,包括了方面的内容,希望对IOS开发有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_147579.html