我正在尝试对 MKAnnotation 应用颜色填充。我发现了一些几乎可以工作的代码,但由于某种原因,填充的图像在应用填充后是颠倒的。
这是我在地图引脚上运行的当前代码。
CGRect rect = CGRectMake(0, 0, self.image.size.width, self.image.size.height);
UIGraphicsBeginImageContext(self.image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, self.image.CGImage);
CGContextSetFillColorWithColor(context, [[UIColor grayColor] CGColor]);
CGContextFillRect(context, rect);
CGContextRotateCTM(context, 90);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage
scale:1.0 orientation:self.image.imageOrientation];
self.image = flippedImage;
这是此代码运行后引脚的外观。
我在想,如果我将当前的图像方向应用到翻转图像上,那会奏效,但那不起作用。我还尝试self.image = img;
完全设置和删除 flippedImage var,但结果仍然相同。