【发布时间】:2011-07-16 21:24:02
【问题描述】:
我需要绘制一个填充有渐变的框。我正在使用 UIView 并覆盖 -drawRect 方法。
这是我的代码(简化):
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);
目前的渐变填充填充了view的整个宽度!我可以做些什么来控制我正在绘制的渐变填充框的宽度?
【问题讨论】:
标签: iphone objective-c draw gradient