見示例代碼繪製的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