【发布时间】:2014-05-22 10:53:35
【问题描述】:
在其中一个应用程序中,我使用CGContextSetFillColorWithColor 在矩形区域中填充颜色。它工作正常并填充正确的颜色,但有时它会填充黑色。我不知道这个问题背后的原因。
代码:
rectangle = CGRectMake(x,y, width, 187/[appDelegate.result count]);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
NSMutableParagraphStyle* p = [NSMutableParagraphStyle new];
p.alignment = NSTextAlignmentCenter;
// p.lineBreakMode=NSLineBreakByWordWrapping;
UIColor *color1 = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0];
NSLog(@"color is %@",color1.CGColor);
CGContextSetFillColorWithColor(context,color1.CGColor);
//CGContextSetFillColor(context, CGColorGetComponents(color1.CGColor));
NSLog(@"rectangle is %f",rectangle.size.height);
CGContextFillRect(context, rectangle);
日志信息:颜色是:
<CGColor 0xc216020> [<CGColorSpace 0xc0124b0> (kCGColorSpaceDeviceRGB)] ( 0.933333 0 0 1)
【问题讨论】:
-
您是否尝试过记录 r、g、b 值?可能是它们没有按预期值出现,有时它们都出现为 0,导致 UIColor 设置为黑色?
标签: ios objective-c cgcolor