首页 技术 正文
技术 2022年11月20日
0 收藏 349 点赞 2,346 浏览 2712 个字

ios swift 实现饼状图进度条

//
// ProgressControl.swift
// L02MyProgressControl
//
// Created by plter on 7/29/14.
// Copyright (c) 2014 jikexueyuan. All rights reserved.
//import UIKitclass 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 UIKitclass 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)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,987
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,503
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,347
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,130
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,842