iphone - MKCircleview Drawings -


How to draw a text in MKCracleview? I have to print a text on the MKMapview overlay, is it possible?

MKOverlayView subclass within this section of my overlay view:

  - (zero) drawMapRect: (MKMapRect) mapRect zoomscale: (MKZoomScale) zoomScale inContext: (CGContextRef) Reference  

You should / something / like this:

  CGContextSetTextMatrix (Reference, CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); // Setup text rendering stuff CGFloat fontHeight = rect.size.height / 2.0f; CGContextSelectFont (reference, "Thonburi", fontHeight, kCGEncodingMacRoman); CGContextSetRGBFillColor (Reference, 0, 0, 0, 1); CGContextSetRGBStrokeColor (Reference, 0, 0, 0, 1); // set string const char * text = [[NSString stringWithFormat: @ "% d", clusters [i]. Count] UTF8String]; Int len ​​= strlen (text); // presenting invisible text CGContextSetTextDrawingMode (context, kCGTextInvisible); CGContextShowTextAtPoint (reference, 0, 0, text, stroken (text)); // Get the real point it was rendered CGPoint pt = CGContextGetTextPosition (reference); // Set text to visible CGContextSetTextDrawingMode (context, kCGTextFillStroke); // Really submit text CGContextShowTextAtPoint (references, rect.origin.x + (0.5f * rect.size.width) - (0.5f * pt.x), // basic + half width - half width of text == Center align text? Rect .origin.y + (1.25f * fontHeight), // hack 1. 1/4 font height (which is the half-reset height) == Center affair. Alliance text. Text, lane);  

This will render a centered text in the middle of the circle

A few warnings about the above code ... it is actually derived from the subclass of MK Overlaypath Weave Within which I need to draw several circles in different places on the overlay scene and thus need a very dynamic method of painting the text in the right place. So the code will not be a drop in the solution for you and is actually a bit more complicated than you. However this will tell you in the right direction.

Please keep in mind that more than some overlay scenes on Mapkit, there is a path of insanity with random crashes and stack marks because the layers consume more and more RAM, thus if you have a few free handfuls If you are overloaded, then I would advise you to go below the MK Overlaypath VUUUUT route.

I pushed my head on the table for almost a month, before I discovered why this accident is happening in such a random time.

My code is for clustering, with each cluster the number of items in that cluster.


Comments