[翻译] GSProgressView
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的更多相关文章
- 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【探索】机器指令翻译成 JavaScript
前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...
- 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...
- 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?
0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
随机推荐
- shiro学习笔记_0600_自定义realm实现授权
博客shiro学习笔记_0400_自定义Realm实现身份认证 介绍了认证,这里介绍授权. 1,仅仅通过配置文件来指定权限不够灵活且不方便.在实际的应用中大多数情况下都是将用户信息,角色信息,权限信息 ...
- JVM-垃圾收集过程的内存管理
JDK1.7 JVM的垃圾收集算法有 1. 标记-清除算法: 2. 复制算法:在商业虚拟机都是使用这种算法来回收新生代的 3. 标记-整理算法: 4.分代收集算法: JDK1.7 JVM的垃圾收集器有 ...
- java7之Special Methods
1.关于<init>与<clinit> At the level of the Java Virtual Machine, every constructor written ...
- Nexus centos 安装
目录 1.安装nexus 2.启动nexus 2.1启动服务器 2.2以后台进程启动: 2.3web访问 3.搭建私服 3.1 界面元素介绍 3.2 仓库集合的界面 3.3 通过网页方式将jar包上传 ...
- [PY3]——内置数据结构(3)——字符串及其常用操作
字符串及其常用操作xmind图 字符串的定义 1. 单引号/双引号 In [1]: s1='hello world' In [2]: s1="hello world" 2. 三对单 ...
- android_serialport_api代码分析
1. 导入Android studio android_serialport_api是一个开源的串口测试工具,代码应该是用eclipse工程(不确定,没用过eclipse,反正不是Android st ...
- 【angular5项目积累总结】列表多选样式框(1)
憋不住想说一下:angular坑太多,各种教程各种不完整,官网还只是简单的画饼充饥,没办法只有自己研究自己总结,便于以后提高工作效率. 第一种: view code list.css :ho ...
- 【转】Java面试题全集(上)
准备从C#转java,在找工作之前准备看看面试题,有幸看到大神的作品,mark一下,以后慢慢看... 2013年年底的时候,我看到了网上流传的一个叫做<Java面试题大全>的东西,认真的阅 ...
- [javaSE] GUI(鼠标事件)
调用Button对象的addMouseListener方法,参数:MouseListener对象,这个类是个接口,需要实现以下方法 mouseClicked mousePressed mouseRel ...
- 微信小程序button选中改样式-实现单选/多选
小程序实现多button单选/多选 红色为选中状态 单选 多选 ①wxss /* pages/button-select/button-select.wxss */ .button_container ...