:아이폰 OS - 코어 그래픽 색상으로 작동하지만, 검정, 흰색과 회색
@implementation StrokedCircle
- (id)initWithRadius:(CGFloat)radius strokeWidth:(CGFloat)strokeWidth strokeColor:(UIColor *)strokeColor
{
self = [super initWithRadius:radius];
if (self)
{
_strokeWidth = strokeWidth;
_strokeColor = strokeColor;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"Drawing with color %@ and stroke width %f", self.strokeColor, self.strokeWidth);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect circleRect = CGRectInset(rect, self.strokeWidth, self.strokeWidth);
CGContextAddEllipseInRect(context, circleRect);
CGContextSetLineWidth(context, self.strokeWidth);
CGContextSetStrokeColor(context, CGColorGetComponents([self.strokeColor CGColor]));
CGContextStrokePath(context);
}
@end
참고 : 슈퍼 클래스는 간단한 원입니다 (UIView
의 sublass) radius
속성이 설정되어 있고보기의 배경색이 clearColor
으로 설정되어 있습니다.
- (void)viewDidLoad
{
[super viewDidLoad];
StrokedCircle *strokedCircle = [[StrokedCircle alloc] initWithRadius:50.0 strokeWidth:1.0 strokeColor:[UIColor blueColor]];
strokedCircle.center = self.view.center;
[self.view addSubview:strokedCircle];
}
이 실제로 잘 작동, 콘솔 출력 :보기 컨트롤러에서
, 나는viewDidLoad
에 다음 코드를 추가
2014-06-14 10:31:58.270 ShapeTester[1445:60b] Drawing with color UIDeviceRGBColorSpace 0 0 1 1 and stroke width 1.000000
과 파란색 원은 화면의 중앙에 표시됩니다. 내가
[UIUColor blackColor]
,
[UIColor grayColor]
, 또는
[UIColor whiteColor]
에 색상을 수정할 때
그러나, 더 원이 더 이상 표시되지 않습니다 (그러나 또한 뷰의 backgroundColor
변화).
누구든지이 동작의 이유를 알고 있습니까? 코어 그래픽이 회색 음영을 그립니 까? 내가 Core Graphics Programming Guide의 적절한 섹션을 통해 읽었지만, 이것에 대해서는 아무 것도 언급되지 않았다.