Created
January 8, 2015 15:10
-
-
Save xujialiang/f8090fa0d0774968ca37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)drawcagradientlayer:(CGRect)rect{ | |
CAGradientLayer *gradient = [CAGradientLayer layer]; | |
gradient.colors = @[(id)[UIColor colorWithRed:0 green:0.8 blue:0 alpha:1.0].CGColor, // light gray | |
(id)[UIColor colorWithRed:0 green:0.8 blue:0 alpha:0.3].CGColor]; // lighter gray | |
// 创建一个Path句柄 | |
CGMutablePathRef pathRef = CGPathCreateMutable(); | |
// 初始化该path到一个初始点 | |
CGPathMoveToPoint(pathRef, &CGAffineTransformIdentity, kYAxisLabelWidth, rect.size.height/2); | |
// 添加一条直线,从初始点到该函数指定的坐标点 | |
CGPathAddLineToPoint(pathRef, &CGAffineTransformIdentity, rect.size.width-kMarginRight, rect.size.height/3); | |
CGPathAddLineToPoint(pathRef, &CGAffineTransformIdentity, rect.size.width-kMarginRight, rect.size.height/2); | |
CGPathAddLineToPoint(pathRef, &CGAffineTransformIdentity, kYAxisLabelWidth, rect.size.height/2); | |
// 关闭该path | |
CGPathCloseSubpath(pathRef); | |
gradient.frame = CGPathGetBoundingBox(pathRef); | |
gradient.startPoint=CGPointMake(0, 0); | |
gradient.endPoint=CGPointMake(1, 0); | |
CAShapeLayer *mask = [CAShapeLayer layer]; | |
CGAffineTransform translation = CGAffineTransformMakeTranslation(-CGRectGetMinX(gradient.frame), | |
-CGRectGetMinY(gradient.frame)); | |
mask.path = CGPathCreateCopyByTransformingPath(pathRef, | |
&translation); | |
gradient.mask = mask; | |
[self.layer addSublayer:gradient]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment