在 MKPolygonView 中绘制简单文本
您好,我尝试在 MKPolygonView 中绘制文本。我创建了 MKPolygonView 的子类并将其添加到我的 MKMapView 中。多边形显示正确,但我看不到文本。谁能帮助我吗?
-(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];
}
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相当确定您需要使用 CoreGraphics 在您的 drawMapRect 覆盖中进行任何类型的绘图。下面的代码尚未编译,因此我不能保证它可以开箱即用,但沿着这些思路的一些东西可能会完成这项工作。
I'm fairly certain that you need to use CoreGraphics for any kind of drawing in your drawMapRect override. The code below has not been compiled so I can't guarantee that it will work out of the box, but something along these lines will probably do the job.
我认为您将能够通过 将上下文推送到 UI 图形上下文堆栈,然后将其弹出,如下所示:
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: