开发者

iPhone : can't control the width of drawing gradients?

I need to draw a box filled with a gradient. I'm开发者_如何学C using a UIView and overwriting the -drawRect method.

Here is my code (simplified):

CGContextRef c = UIGraphicsGetCurrentContext();     
CGFloat components[8] = {158.0/255.0,36.0/255.0,134.0/255.0,1.0,115.0/255.0,26.0/255.0,93.0/255.0,1.0};

        CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();

        CGFloat locations[2] = {0.0,1.0};
        CGGradientRef glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, 2);

        CGPoint topCenter = CGPointMake(10, 0);
        CGPoint bottomCenter = CGPointMake(10, 10);
        CGContextDrawLinearGradient(c, glossGradient, topCenter, bottomCenter, 0);

The gradient fill at present fills the entire width of the view! What can I do to control the width of the gradient-filled box I'm drawing?


Nevermind.. Found the answer. I need to clip my CGContextRef to match the CGRect I wanted:

CGContextClipToRect(c, currentBounds);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜