在我的应用中,我集成了iOS版Google Map sdk。想显示带有序列号的标记。
标记的数量将在运行时确定,因此我不能简单地为每个标记放置一个法师,以某种方式我必须以编程方式创建它。我是一张没有序列的图像。我的想法是使用该图像创建图像,并在创建图像时在其上写上数字。但是不知道如何。
任何帮助,将不胜感激。
最佳答案
感谢@knshn给我评论链接。这是我的解决方案
-(UIImage *)getImage :(UIImage *)icon stop:(NSString *)stopNumber color:(UIColor *)color
{
// create label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, icon.size.width,icon.size.height)];
[label setText:stopNumber];
[label setTextColor:color];
[label setFont:[UIFont boldSystemFontOfSize:11]];
label.textAlignment = NSTextAlignmentCenter;
// use UIGraphicsBeginImageContext() to draw them on top of each other
//start drawing
UIGraphicsBeginImageContext(icon.size);
//draw image
[icon drawInRect:CGRectMake(0, 0, icon.size.width, icon.size.height)];
//draw label
[label drawTextInRect:CGRectMake((icon.size.width - label.frame.size.width)/2, -5, label.frame.size.width, label.frame.size.height)];
//get the final image
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}