我正在尝试在MKMapView上绘制一些包含文本的圆形覆盖层。 我已经对MKCircleView进行了子类化,在其中放置了以下内容(基于此),但文本不会显示。圆圈正确显示。(也尝试了第一个回答的解决方案,结果相同)。
-(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
他们正常吗?我错过了什么?谢谢。
CGPoint center = CGPointMake(circleRect.origin.x + circleRect.size.width /2,circleRect.origin.y + circleRect.size.height /2); CGPoint textstart = CGPointMake(center.x - size.width/2, center.y - size.height /2 );`
- Templar