GSProgressView

本人极不推荐使用drawRect的方式来绘制下载进度条,无论机器的性能怎么高,使用drawRect用于绘制图形都是低效的。

A cute little circular progress view for iOS

一款轻巧的显示圆形进度的的view,用于iOS开发

Installation - 安装

Drag GSProgressView.h and GSProgressView.m into your project.

将GSProgressView.h与GSProgressView.m拖到你的工程当中。

Serving suggestion - 建议的使用方式

GSProgressView *pv = [[GSProgressView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
pv.color = [UIColor redColor];
pv.progress = 0.6;
[myView addSubview:pv];
GSProgressView.h + GSProgressView.m
//
// GSProgressView.h
//
// Created by Simon Whitaker on 14/11/2012.
// Copyright (c) 2012 Goo Software Ltd. All rights reserved.
// #import <UIKit/UIKit.h> @interface GSProgressView : UIView @property (nonatomic) CGFloat progress;
@property (strong, nonatomic) UIColor *color UI_APPEARANCE_SELECTOR;
@property (strong, nonatomic) UIColor *tickColor UI_APPEARANCE_SELECTOR; @end
//
// GSProgressView.m
//
// Created by Simon Whitaker on 14/11/2012.
// Copyright (c) 2012 Goo Software Ltd. All rights reserved.
// #import "GSProgressView.h"
#import <QuartzCore/QuartzCore.h> @implementation GSProgressView - (void)commonInit {
self.backgroundColor = [UIColor clearColor];
} - (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
} - (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
} - (void)setProgress:(CGFloat)progress {
if (progress > 1.0) progress = 1.0; if (progress != _progress) {
_progress = progress;
[self setNeedsDisplay];
}
} - (void)drawRect:(CGRect)rect {
if ([self color] == nil)
[self setColor:[UIColor blackColor]]; CGPoint center = CGPointMake(rect.size.width/, rect.size.height/);
CGFloat radius = MIN(rect.size.width, rect.size.height)/; // Start a path
UIBezierPath *path = [UIBezierPath bezierPath]; // Move to centre and draw an arc. [path moveToPoint:center];
[path addArcWithCenter:center
radius:radius
startAngle: - M_PI_2 // zero degrees is east, not north, so subtract pi/2
endAngle: * M_PI * [self progress] - M_PI_2 // ditto
clockwise:YES];
[path closePath]; // If progress is 1.0, show a tick mark in the centre of the circle
if ([self progress] == 1.0) {
/*
First draw a tick that looks like this: A---F
| |
| E-------D
| |
B-----------C (Remember: (0,0) is top left)
*/
UIBezierPath *tickPath = [UIBezierPath bezierPath];
CGFloat tickWidth = radius/;
[tickPath moveToPoint:CGPointMake(, )]; // A
[tickPath addLineToPoint:CGPointMake(, tickWidth * )]; // B
[tickPath addLineToPoint:CGPointMake(tickWidth * , tickWidth * )]; // C
[tickPath addLineToPoint:CGPointMake(tickWidth * , tickWidth)]; // D
[tickPath addLineToPoint:CGPointMake(tickWidth, tickWidth)]; // E
[tickPath addLineToPoint:CGPointMake(tickWidth, )]; // F
[tickPath closePath]; // Now rotate it through -45 degrees...
[tickPath applyTransform:CGAffineTransformMakeRotation(-M_PI_4)]; // ...and move it into the right place.
[tickPath applyTransform:CGAffineTransformMakeTranslation(radius * 0.43, radius)]; // Account for non-square views
CGFloat xOffset = rect.size.width/ - radius;
CGFloat yOffset = rect.size.height/ - radius;
[tickPath applyTransform:CGAffineTransformMakeTranslation(xOffset, yOffset)]; // Add fill color if it's set
if (self.tickColor) {
[[self tickColor] setFill];
[tickPath fill];
} // Add the tick path to the existing circle path
[path appendPath:tickPath];
};
path.usesEvenOddFillRule = YES; [[self color] setFill];
[path fill];
} #pragma mark - Accessibility - (BOOL)isAccessibilityElement {
return YES;
} - (NSString *)accessibilityLabel {
return NSLocalizedString(@"Progress", @"Accessibility label for GSProgressView");
} - (NSString *)accessibilityValue {
// Report progress as a percentage, same as UISlider, UIProgressView
return [NSString stringWithFormat:@"%d%%", (int)round([self progress] * 100.0)];
} - (UIAccessibilityTraits)accessibilityTraits {
return UIAccessibilityTraitUpdatesFrequently;
} @end

[翻译] GSProgressView的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. C 扩展库 - mysql API

    MySQL API C API Data Structures MYSQL This structure represents handler for one database connection. ...

  2. java值传递与引用传递

    看代码: import java.lang.reflect.Field; public class Test { public static void main(String[] args) { In ...

  3. 【扫盲】】32位和64位Windows的区别

    用户购买windows安装盘或者重新安装操作系统的时候,通常会遇到这个问题,就是不知道该如何选择使用32位操作系统和64位操作系统,有人说64位系统速度快,其实理论上确实是这样,不过具体还要根据你的个 ...

  4. js 列表选择

    首选定义数组,然后进行操作时遍历数组获取选中值 function getSelect(userId) { //var userId = userCheckBox.value; //标记删除还是添加 v ...

  5. 跨域 cookies

    script标签请求的js脚本,如果跨域了,请求会带有外域的cookies信息. XMLHttpRequest请求跨域时,需要有Access-Control-*等的头信息,如果需要将cookies传输 ...

  6. C# 中的隐式类型转换(运算时的隐式转换)和显示类型转换

    区别: 隐式转换失败编译会报错. 显示转换有可能精度丢失. 根据项目的编译设置,显示转换溢出可能会报错,如果设置溢出且未使用checked检查,运行时如果发生溢出会产出未知的计算结果. 在数字运算时, ...

  7. MySQL---7、常用操作

    1.表列的添加.修改和删除 2.视图 3.字符集和校对集 4.触发器相关知识

  8. Vue 多路由文件的合并

    Vue 多路由文件的合并 1.使用的是ES6 数组的合并方法 let routes = new Set([...routes1, ...homerouters]);2.两个路由文件,导出的实际上就是一 ...

  9. Cheatsheet: 2018 04.01 ~ 04.30

    Web Writing VS Code Extensions with TypeScript Docker How to write excellent Dockerfiles Raspberry P ...

  10. GIT 基础-基础命令

    环境 centos7 1.安装 #yum install git 2.创建本地仓库 ( 这里用 /www/git) 这里里有个隐藏的文件夹 ```.git``` 为git仓库的配置文件夹, 不可随意修 ...