[翻译] 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 ...
随机推荐
- Windows Server 2003、2008、2012系统的安装
说在前面的话 Windows Server 2003,和Windows XP十分相似,可以简单地认为Windows Server 2003是在Windows XP的基础上多了一些服务器管理和操作的功能 ...
- Java jstl标签使用总结
1.在jsp文件中引用 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&g ...
- WPF中Style文件引用另一个Style文件中的样式
第1种方法: 直接在当前Style文件(*.xaml)文件中使用: <ResourceDictionary.MergedDictionaries>来进行合并 <!-- 关键是注意so ...
- [中英对照]User-Space Device Drivers in Linux: A First Look | 初识Linux用户态设备驱动程序
如对Linux用户态驱动程序开发有兴趣,请阅读本文,否则请飘过. User-Space Device Drivers in Linux: A First Look | 初识Linux用户态设备驱动程序 ...
- 2016年学习JavaScript是怎样的一种体验(转)
转自:http://www.zcfy.cc/article/how-it-feels-to-learn-javascript-in-2016-hacker-noon-1871.html 在这篇文章的写 ...
- <数据挖掘导论>读书笔记9聚类分析
1. 聚类分析仅根据在数据中发现的描述对象及其关系的信息,将数据对象分组. 其目标是组内的对象相互之间是相似的或者相关的,而不同组中的对象是不同的或者不相关的. 2.聚类分析的重要技术 K均值:K均值 ...
- CNN理解与实现
CNN理解与实现 组成部分 Convolution Layer Pool Layer: Max-pooling layer Average-pooling layer Full Connected(F ...
- 每天一道leetcode234-回文链表
考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:”乔戈里峰” 前言 2018. ...
- WPF判断两个时间大小避免误差
进行查询操作的时候,经常用到判断开始时间和结束时间大小的条件,由于从控件上获取的时间除了年月日时分秒,还包括毫秒.微秒等,导致直接判断时间大小的时候会产生一些误差,如下: 结果分析:年月日时分秒一致的 ...
- MFC—— AfxMessageBox
AfxMessageBox 错误C2665: “AfxMessageBox”: 2 个重载中没有一个可以转换所有参数类型 1,楼主发表于:2007-01-01 03:56:34同样的语句, ...