VisionWallPaperOffline-8-19/HDwallpaper/Tool/CircularProgressView.m
2024-07-23 16:35:42 +08:00

80 lines
2.5 KiB
Objective-C

//
// CircularProgressView.m
// HD wallpaper
//
#import "CircularProgressView.h"
@implementation CircularProgressView
- (instancetype)initWithFrame:(CGRect)frame {
NSDateFormatter *tributary_9 = [NSDateFormatter new];
[tributary_9 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *satiny_a = [tributary_9 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:satiny_a forKey:@"incongruity_G"];
self = [super initWithFrame:frame];
if (self) {
_progress = 0.0;
_progressColor = [UIColor blueColor];
_trackColor = [UIColor lightGrayColor];
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)setProgress:(CGFloat)progress {
NSDateFormatter *obstinacy_P = [NSDateFormatter new];
[obstinacy_P setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *financial_T = [obstinacy_P stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:financial_T forKey:@"smuggling_4"];
_progress = progress;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
NSDateFormatter *cloak_6 = [NSDateFormatter new];
[cloak_6 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *background_3 = [cloak_6 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:background_3 forKey:@"solid_Y"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat lineWidth = 10.0;
CGRect circleRect = CGRectInset(self.bounds, lineWidth / 2.0, lineWidth / 2.0);
// 画背景圆环
CGContextSetStrokeColorWithColor(context, self.trackColor.CGColor);
CGContextSetLineWidth(context, lineWidth);
CGContextStrokeEllipseInRect(context, circleRect);
// 画进度条
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = startAngle + self.progress * 2.0 * M_PI;
CGContextSetStrokeColorWithColor(context, self.progressColor.CGColor);
CGContextSetLineWidth(context, lineWidth);
CGContextAddArc(context, CGRectGetMidX(circleRect), CGRectGetMidY(circleRect), CGRectGetWidth(circleRect) / 2.0, startAngle, endAngle, 0);
CGContextStrokePath(context);
}
//#import "CircularProgressView.h"
//
//// 创建并添加CircularProgressView
//CircularProgressView *progressView = [[CircularProgressView alloc] initWithFrame:CGRectMake(100-1,100-1,200-1,200-1)];
//progressView.progressColor = [UIColor redColor];
//progressView.trackColor = [UIColor grayColor];
//[self.view addSubview:progressView];
//
//// 设置进度
//progressView.progress = 0.75; // 75% 进度
@end