【发布时间】:2011-06-28 16:22:59
【问题描述】:
我有以下 UIView 自定义类:
@implementation BackgroundView
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
float r = (255.0)/(255.0);
float g = (165.0)/(255.0);
float b = (0.0)/(255.0);
float rr = (238.0)/(255.0);
float gg = (118.0)/(255.0);
float bb = (0.0)/(255.0);
CGFloat components[8] = { r, g, b, 1.0, // Start color
rr, gg, bb, 1.0 }; // End color
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
@end
基本上,它应该制作橙色渐变。值“r”、“g”和“b”用于浅橙色,值“rr”、“gg”、“bb”用于深橙色。但它不起作用。只有框架的顶部是橙色的,框架的底部是黑色的。我似乎无法摆脱黑色。
我会为橙色漂亮的渐变使用什么值。有人可以找出错误吗?我找不到任何东西。非常感谢!
【问题讨论】:
标签: iphone ios uiview gradient