2

こんにちは、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];
}
4

2 に答える 2

0

次のように、コンテキストを UI グラフィックス コンテキスト スタックにプッシュし、その後ポップすることで、UIKit 描画を使用できると思います。

UIGraphicsPushContext(context);
[[UIColor redColor] set];
[t drawInRect:...];
etc, etc.
UIGraphicsPopContext();
于 2010-11-12T16:09:45.123 に答える
0

drawMapRect オーバーライドであらゆる種類の描画に CoreGraphics を使用する必要があることは確かです。以下のコードはコンパイルされていないため、すぐに動作することを保証できませんが、これらの行に沿った何かがおそらく機能します.

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

  // The base implementation does nothing so this isn't needed
  //[super drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context];

  NSString * t= @"Test" ;
  CGPoint point = [self pointForMapPoint:mapRect.origin];

  CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
  CGContextSelectFont (context, "Helvetica", 20.0f, kCGEncodingFontSpecific);
  CGContextShowTextAtPoint(context, point.x, point.y, [t UTF8String], [t length]);
}
于 2010-11-12T15:59:32.153 に答える