见示例代码绘制的CALayer,其中U可以添加到一个UIView的层属性。
-(void)drawInContext:(CGContextRef)theContext
{
// self.opacity = .5;
CGMutablePathRef thePath = CGPathCreateMutable();
//CGPathMoveToPoint(thePath,NULL,100.0f,200.f);
CGPoint aOnePoint=CGPointMake(cgpoint.x,tipPoint.y);
CGPoint aTwoPoint=CGPointMake(cgpoint.x+5,460);
CGPoint aThreePoint=CGPointMake(320,100);
CGPoint aFourPoint=CGPointMake(320,tipPoint.y-25);
CGPoint points[]={aOnePoint,aTwoPoint,aFourPoint};
CGPathAddLines(thePath, NULL,points,3);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
//CAGradientLayer here...using the CGCreateGradient methods.
CGContextSetLineWidth(theContext,2.0f);
CGSize theShadowSize = CGSizeMake(4.0f,4.0f);
CGContextSetShadowWithColor(theContext, theShadowSize,3,[UIColor darkGrayColor].CGColor);
CGContextSetFillColorWithColor(theContext,[UIColor redColor].CGColor);
CGContextFillPath(theContext);
CFRelease(thePath);
}
这种方式,您可以绘制自己的层,并把它添加到.layer视图的属性。 请注意,我们必须覆盖- (void)drawInContext:(CGContextRef)theContext
以拥有自定义图层。可能需要调用
希望帮助..
呃,我的问题是关于如何绘制它如何使它设置为顶层的梯度? – HenryH 2011-04-25 02:50:10