实现原理:我的实现原理就是在视图上面画三个圆弧,较大的圆弧的宽度为5.f,上面的字体通过圆的坐标进行排布,然后通过改变label的旋转角度来条整他的位置
#define pi 3.14159265359
#define DEGREES_TO_RADIANS(degrees) ((pi * degrees)/ 180)
#import "View.h"
@implementation View
-(instancetype)initWithFrame:(CGRect)frame{
if ([super initWithFrame:frame]) {
}
[self creatUI];
return self;
}
-(void)creatUI{
self.backgroundColor = [UIColor colorWithRed:255.0 /255 green:119/255.0 blue:150.0 /255 alpha:1];
[self closeLine];
[self settitle];
[self setBigLabelTitle];
}
-(void)setBigLabelTitle{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 50)];
label.text = @"信用较差";
label.center =CGPointMake(self.frame.size.width /2, 240);
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
[self addSubview:label];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 50)];
label2.text = @"600";
label2.center =CGPointMake(self.frame.size.width /2, 200);
label2.textAlignment = NSTextAlignmentCenter;
label2.textColor = [UIColor whiteColor];
label2.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
[self addSubview:label2];
}
-(void)settitle{
NSArray *stateArray = @[@"较差",@"差",@"良好",@"较好",@"优秀"];
for (int i = 1; i <= stateArray.count; i ++) {
UILabel *label = [[UILabel alloc]init];
label.frame = CGRectMake(0, 0, 40, 25);
label.center = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:36*i +60 andWithRadius:100];
label.text = stateArray[i-1];
label.font = [UIFont systemFontOfSize:10];
if (i==1) {
label.transform = CGAffineTransformMakeRotation(-M_PI /2);
}else if (i==2){
label.transform = CGAffineTransformMakeRotation(-M_PI /(i+1));
}else if (i==3){
label.transform = CGAffineTransformMakeRotation(-M_PI /7);
}else if (i==4){
label.transform = CGAffineTransformMakeRotation(M_PI /4);
}else if (i==5){
label.transform = CGAffineTransformMakeRotation(M_PI /2.5);
}
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
[self addSubview:label];
}
}
-(void)closeLine{
CGPoint point = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:155 andWithRadius:140];
UIImageView *imagev = [[UIImageView alloc]init];
imagev.frame =CGRectMake(0, 0, 10, 10);
imagev.center = point;
imagev.layer.cornerRadius = 5;
imagev.backgroundColor = [UIColor whiteColor];
[self addSubview:imagev];
}
-(CGPoint) calcCircleCoordinateWithCenter:(CGPoint) center andWithAngle : (CGFloat) angle andWithRadius: (CGFloat) radius{
CGFloat x2 = radius*sinf(angle*M_PI/180);
CGFloat y2 = radius*cosf(angle*M_PI/180);
return CGPointMake(center.x-x2, center.y+y2);
}
- (void)drawRect:(CGRect)rect
{
UIColor *color = [UIColor colorWithRed:255/255.0 green:161/255.0 blue:182/255.0 alpha:1];
[color set]; //设置线条颜色
UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width /2, 230)
radius:140
startAngle:0
endAngle:DEGREES_TO_RADIANS(180)
clockwise:NO];
aPath.lineWidth = 2.0;
aPath.lineCapStyle = kCGLineCapSquare; //线条拐角
aPath.lineJoinStyle = kCGLineCapSquare; //终点处理
[aPath stroke];
UIColor *color3 = [UIColor colorWithRed:255/255.0 green:161/255.0 blue:182/255.0 alpha:1];
[color3 set]; //设置线条颜色
UIBezierPath* aPath3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width /2, 230)
radius:120
startAngle:0
endAngle:DEGREES_TO_RADIANS(180)
clockwise:NO];
aPath3.lineWidth = 8.0;
aPath3.lineCapStyle = kCGLineCapSquare; //线条拐角
aPath3.lineJoinStyle = kCGLineCapSquare; //终点处理
[aPath3 stroke];
UIColor *color2 = [UIColor whiteColor];
[color2 set]; //设置线条颜色
UIBezierPath* aPath2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width /2, 230)
radius:140
startAngle:-90
endAngle:DEGREES_TO_RADIANS(180)
clockwise:NO];
aPath2.lineWidth = 2.0;
aPath2.lineCapStyle = kCGLineCapSquare; //线条拐角
aPath2.lineJoinStyle = kCGLineCapSquare; //终点处理
[aPath2 stroke];
for (int i = 1; i <=30; i++) {
UIColor *color55 = [UIColor colorWithRed:255/255.0 green:183/255.0 blue:200/255.0 alpha:1];
[color55 set];
//创建path
UIBezierPath * path = [UIBezierPath bezierPath];
//设置线宽
path.lineWidth = 3;
//线条拐角
path.lineCapStyle = kCGLineCapSquare;
//终点处理
path.lineJoinStyle = kCGLineCapSquare;
CGPoint point = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:6 *i +90 andWithRadius:124];
CGPoint point2 = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:6*i +90 andWithRadius:116];
[path moveToPoint:point];
[path addLineToPoint:point2];
[path closePath];
//根据坐标点连线
[path stroke];
}
for (int i = 0; i <6; i++) {
UIColor *color55 = [UIColor whiteColor];
[color55 set];
//创建path
UIBezierPath * path = [UIBezierPath bezierPath];
//设置线宽
path.lineWidth = 3;
//线条拐角
path.lineCapStyle = kCGLineCapSquare;
//终点处理
path.lineJoinStyle = kCGLineCapSquare;
CGPoint point = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:30 *i +90 andWithRadius:124];
CGPoint point2 = [self calcCircleCoordinateWithCenter:CGPointMake(self.frame.size.width /2, 230) andWithAngle:30 *i +90 andWithRadius:116];
[path moveToPoint:point];
[path addLineToPoint:point2];
[path closePath];
//根据坐标点连线
[path stroke];
}
}
@end
网友评论