Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To draw a circle with a gradient, you have to provide an own annotation view class, as none of the existing ones support that. What you can do is you can override the method <code>- (void)fillPath:(CGPathRef)path inContext:(CGContextRef)context</code> in a subclass of <code>MKCircleView</code>. Here is some code (non-optimized, with hardcoded fill parameters) to get you started:</p> <pre><code>@interface TWOGradientCircleView : MKCircleView @end @implementation TWOGradientCircleView - (void)fillPath:(CGPathRef)path inContext:(CGContextRef)context { CGRect rect = CGPathGetBoundingBox(path); CGContextAddPath(context, path); CGContextClip(context); CGFloat gradientLocations[2] = {0.6f, 1.0f}; // Start color white with 0.25 alpha, // End color green with 0.25 alpha CGFloat gradientColors[8] = {1.0f, 1.0f, 1.0f, 0.25f, 0.0f, 1.0f, 0.0f, 0.25f}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradientColors, gradientLocations, 2); CGColorSpaceRelease(colorSpace); CGPoint gradientCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); CGFloat gradientRadius = MIN(rect.size.width, rect.size.height) / 2; CGContextDrawRadialGradient(context, gradient, gradientCenter, 0, gradientCenter, gradientRadius, kCGGradientDrawsAfterEndLocation); CGGradientRelease(gradient); } </code></pre> <p>To use it, just replace <code>MKCircleView</code> with <code>TWOGradientCircleView</code>:</p> <pre><code>- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay { MKCircleView *circleView = [[TWOGradientCircleView alloc] initWithOverlay:overlay]; return circleView; } </code></pre> <p>If you would like to use an image instead of drawing the gradient, you can replace the gradient drawing above with image drawing. As zooming in would then blur the image, you should either disable zoom, or tile the image as Apple demonstrated in a session at WWDC10 (see <a href="https://github.com/klokantech/Apple-WWDC10-TileMap" rel="noreferrer">here</a> for a repository with their sample code). Setting a <code>UIColor</code> with a pattern image does not work for a radius of 15000 (unless you use a really, really huge image ;)).</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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