我正在尝试在 MKMapView 上绘制一些包含文本的圆形叠加层。我对 MKCircleView 进行了子类化,我在其中放置了以下内容(基于this),但没有出现文本。圆圈正确显示。(也尝试了第一个响应的解决方案,结果相同)。
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
NSString * t= @"XXXXX\nXXXX" ;
UIGraphicsPushContext(context);
CGContextSaveGState(context);
[[UIColor redColor] set];
CGRect overallCGRect = [self rectForMapRect:[self.overlay boundingMapRect]];
NSLog(@"MKC : %lf, %lf ----> %lf , %lf ", mapRect.origin.x ,mapRect.origin.y , overallCGRect.origin.x, overallCGRect.origin.y);
[t drawInRect:overallCGRect withFont:[UIFont fontWithName:@"Arial" size:10.0] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
CGContextRestoreGState(context);
UIGraphicsPopContext();
}
调试时,我得到这样的值
MKC : 43253760.000000, 104071168.000000 ----> 1.776503 , 1.999245
MKC : 43253760.000000, 104071168.000000 ----> -1.562442 , -2.043090
他们正常吗?我错过了什么?
谢谢。