首先看一下效果:
我定义了一个timer类,通过调用它来实现这样的效果。下面来看代码:
// timer.h
#import
@interface timer : UIView
- (id)initWithFrame:(CGRect)frame arcWidth:(double)width current:(double)current total:(double)total;
@end
// TimeProportion.m
#import "TimeProportion.h"
#define PI 3.14159265358979323846
@implementation TimeProportion
static float arcWidth; //圆弧的宽度
static double pieCapacity; //角度增量值
static inline float radians(double degrees) {
return degrees * PI / 180;
}
- (id)initWithFrame:(CGRect)frame arcWidth:(double)width current:(double)current total:(double)total
{
self = [super initWithFrame:frame];
if (self) {
arcWidth=width;
pieCapacity=360*current/total;