我创建了一个Google地图视图,我在其各自的位置设置标记,并在其上添加一些文字。现在我想根据缩放更改该文本的大小,意味着在缩小时尺寸应该更大,在地图上放大时要放大。如何实现相同?我尝试了不同的逻辑但失败了。我正在使用以下函数
创建标记文本//将文字添加到UIImage
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1 red:(int)red green:(int)green blue:(int)blue alpha:(float)Alpha{
int w = img.size.width;
int h = img.size.height;
//lon = h - lon;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = (CGBitmapInfo) kCGImageAlphaPremultipliedFirst;
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, bitmapInfo);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
char * text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
//Here I set size of text
CGContextSelectFont(context, "HelveticaNeue-Bold", 15, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowTextAtPoint(context, 0, 0, text, strlen(text));
// Then get the position of the text and set the mode back to visible:
CGPoint pt = CGContextGetTextPosition(context);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 0, 0, 0, 1); // black - for shadow
CGContextShowTextAtPoint(context, (w/2) - (pt.x / 2) + 1, h/2, text, strlen(text));
CGContextSetRGBFillColor(context, red, green, blue, Alpha); // white - for text
CGContextShowTextAtPoint(context, (w/2) - (pt.x / 2), h/2, text, strlen(text));
CGImageRef imageMasked=nil;
imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
} // addText