Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following snippet is useful for drawing a center text string using an Annotation custom image as a reference:</p> <p>CustomAnnotation.h</p> <pre><code>@interface CustomAnnotation : MKAnnotationView [...] </code></pre> <p>CustomAnnotation.m</p> <pre><code>[...] - (void)drawRect:(CGRect)rect { ClusterAnnotation *associatedAnnotation = (CustomAnnotation *)self.annotation; if (associatedAnnotation != nil) { CGContextRef context = UIGraphicsGetCurrentContext(); NSString *imageName = @"custom_image.png"; CGRect contextRect = CGRectMake(0, 0, 42.0, 42.0); CGFloat fontSize = 14.0; [[UIImage imageNamed:imageName] drawInRect:contextRect]; NSInteger myIntegerValue = [associatedAnnotation.dataObject.myIntegerValue integerValue]; NSString *myStringText = [NSString stringWithFormat:@"%d", myIntegerValue]; UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; CGSize fontWidth = [myStringText sizeWithFont:font]; CGFloat yOffset = (contextRect.size.height - fontWidth.height) / 2.0; CGFloat xOffset = (contextRect.size.width - fontWidth.width) / 2.0; CGPoint textPoint = CGPointMake(contextRect.origin.x + xOffset, contextRect.origin.y + yOffset); CGContextSetTextDrawingMode(context, kCGTextStroke); CGContextSetLineWidth(context, fontSize/10); CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] CGColor]); [myStringText drawAtPoint:textPoint withFont:font]; CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]); [myStringText drawAtPoint:textPoint withFont:font]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload