0

Currently, I am attempting to draw a simple dot inside of a cell's UIImageView's UIImage. I am attempting to accomplish the same thing that the calendar application the iPhone has when an event is represented by a calendar.

[[event calendar] CGColor] 

is an EKEvent object which logs UIDeviceRGBColorSpace 0.509804 0.584314 0.686275 1

I attempt to create a small dot whose color is [[event calendar] CGColor]. Heres what I am currently trying to do:

CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]);
CGContextAddEllipseInRect(contextRef,(CGRectMake (12.f, 5.f, 4.f, 5.f)));
CGContextDrawPath(contextRef, kCGPathFill);
CGContextStrokePath(contextRef);
cell.imageViewPic.image = UIGraphicsGetImageFromCurrentImageContext();

But here are the errors I'm getting:

 MYSCHEDULER[21445] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
 MYSCHEDULER[21445] <Error>: CGContextAddEllipseInRect: invalid context 0x0
 MYSCHEDULER[21445] <Error>: CGContextDrawPath: invalid context 0x0
 MYSCHEDULER[21445] <Error>: CGContextDrawPath: invalid context 0x0

I don't understand what I'm doing wrong... Why is the context invalid?

4

1 回答 1

2

正如我所看到的,您正在尝试获取您所做的绘图的图像,然后将其添加到 imageViewPic。以下是你应该做的让它工作:

UIGraphicsBeginImageContext(CGSizeMake(5.0f,5.0f)); 
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]);
CGContextFillEllipseInRect(contextRef,(CGRectMake (0.f, 0.f, 5.f, 5.f)));
UIImage *drawingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

cell.imageViewPic.image = drawingImage;
于 2013-08-26T04:48:19.053 回答