在MKPolygonView中绘制简单的文本 [英] Draw simple Text in a MKPolygonView

查看:121
本文介绍了在MKPolygonView中绘制简单的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试在MKPolygonView中绘制文本.我制作了MKPolygonView的子类,并将其添加到我的MKMapView中.多边形显示正确,但看不到文本.谁能帮我吗?

Hello I try to draw text in a MKPolygonView. I made a subclass of MKPolygonView and added it to my MKMapView. The Polygon shows up correctly, but I can't see the Text. Can anyone help me?

-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{

  [super drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context];

  CGRect overallCGRect = [self rectForMapRect:self.overlay.boundingMapRect];
  UIFont* font = [UIFont fontWithName:@"ArialRoundedMTBold" size:20.0f]; 

  NSString * t= @"Test";
  [[UIColor redColor] set];
  [t drawInRect:overallCGRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
}

推荐答案

我认为您可以通过

I think you'll be able to use the UIKit drawing by pushing the context to the UI graphics context stack, then popping it afterwards, like so:

UIGraphicsPushContext(context);
[[UIColor redColor] set];
[t drawInRect:...];
etc, etc.
UIGraphicsPopContext();

这篇关于在MKPolygonView中绘制简单的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆