//
//? ENDHypView.m
//? ENDHyp
//
//? Created by 周長鑫 on 2018/2/2.
//? Copyright ? 2018年 endymion. All rights reserved.
//
#import "ENDHypView.h"
@implementation ENDHypView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
? ? // Drawing code
? ? //獲取上下文
? ? CGContextRef currentRef = UIGraphicsGetCurrentContext();
? ? //確定同心圓的圓心
? ? CGPointcenter;
? ? center.x = self.bounds.origin.x + self.bounds.size.width / 2.0;
? ? center.y = self.bounds.origin.y + self.bounds.size.height / 2.0;
? ? //設(shè)定最大半徑
? ? float maxRadius = hypot(self.bounds.size.width, self.bounds.size.height) / 2.0;
? ? //設(shè)定圓圈顏色
? ? CGContextSetStrokeColorWithColor(currentRef, [[UIColor lightGrayColor] CGColor]);
? ? //設(shè)定線寬
? ? CGContextSetLineWidth(currentRef, 10.0);
? ? //畫同心圓
? ? for(floatcurrentRadius = maxRadius; currentRadius >0; currentRadius -=20) {
? ? ? ? CGContextAddArc(currentRef, center.x, center.y, currentRadius,0,M_PI*2,YES);
? ? ? ? CGContextStrokePath(currentRef);
? ? }
? ? CGContextMoveToPoint(currentRef, center.x,100);
? ? CGContextAddLineToPoint(currentRef, center.x-150,600);
? ? CGContextAddLineToPoint(currentRef, center.x+150,600);
? ? //啊啊啊啊?。?!我開始就是忘了這行
? ? CGContextClosePath(currentRef);
? ? //開始填色
? ? CGContextSaveGState(currentRef);
? ? CGContextClip(currentRef);
? ? CGFloatlocations[2]? = {0.0,1.0};
? ? CGFloatcomponents[8] = {1.0,0.0,0.0,1.0,// 起始顏色為紅色
? ? ? ? 1.0,1.0,0.0,1.0};// 起始顏色為黃色
? ? CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
? ? CGGradientRefgradient =CGGradientCreateWithColorComponents(colorSpaceRef, components, locations,2);
? ? CGContextDrawLinearGradient(currentRef, gradient,CGPointMake(center.x,100),CGPointMake(center.x,600),0);
? ? CGContextRestoreGState(currentRef);
? ? //填色結(jié)束
? ? //做陰影
? ? CGContextSaveGState(currentRef);
? ? CGContextSetShadow(currentRef, CGSizeMake(4, 7), 3);
? ? UIImage*image = [UIImageimageNamed:@"logo.png"];
? ? [imagedrawInRect:CGRectMake(100,100,self.bounds.size.width-200,self.bounds.size.height-200)];
? ? CGContextRestoreGState(currentRef);
? ? //做陰影結(jié)束
}
-(instancetype)initWithFrame:(CGRect)frame
{
? ? if(self= [superinitWithFrame: frame]){
? ? ? ? [self setBackgroundColor:[UIColor clearColor]];
? ? }
? ? return self;
}
@end
結(jié)果圖:
