目前,我正在尝试在单元格的 UIImageView
的 UIImage
中绘制一个简单的点。当事件由日历表示时,我正在尝试完成与 iPhone 日历应用程序相同的事情。
[[event calendar] CGColor]
是一个 EKEvent
对象,记录 UIDeviceRGBColorSpace 0.509804 0.584314 0.686275 1
我尝试创建一个颜色为 [[event calendar] CGColor]
的小点。这是我目前正在尝试做的事情:
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();
但这里是我得到的错误:
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
我不明白我做错了什么...为什么上下文无效?
最佳答案
如我所见,您正在尝试获取您所做绘图的图像,然后将其添加到 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;
关于iphone - 在单元格 UIImageView 的 UIImage 中绘制一个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18436520/