MKOverlayPathView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MapKit.framework
Availability
Available in iOS 4.0 and later.
Companion guide
Declared in
MKOverlayPathView.h
Related sample code

Overview

The MKOverlayPathView class represents a generic overlay that draws its contents using a CGPathRef data type. You can use this class to implement simple path-based overlay views or subclass it to define additional drawing behaviors. The default drawing behavior of this class is to apply the object’s current fill attributes, fill the path, apply the current stroke attributes, and then stroke the path.

If you subclass, you should override the createPath method and use that method to build the appropriate path for the overlay. You can invalidate this path as needed and force the path to be recreated using whatever new data your subclass has obtained.

Tasks

Accessing the Drawing Attributes

Creating and Managing the Path

Drawing the Path

Properties

fillColor

The fill color to use for the path.

@property (retain) UIColor *fillColor
Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MKOverlayPathView.h

lineCap

The line cap style to apply to the open ends of the path.

@property CGLineCap lineCap
Discussion

The line cap style is applied to the start and end points of any open subpaths. This property does not affect closed subpaths. The default line cap style is kCGLineCapButt.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

lineDashPattern

An array of numbers indicating the dash pattern for paths.

@property (copy) NSArray *lineDashPattern
Discussion

The array contains one or more NSNumber objects that indicate the lengths (measured in points) of the line segments and gaps in the pattern. The values in the array alternate, starting with the first line segment length, followed by the first gap length, followed by the second line segment length, and so on.

This property is set to nil by default, which indicates no line dash pattern.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

lineDashPhase

The

@property CGFloat lineDashPhase
Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

lineJoin

The line join style to apply to corners of the path.

@property CGLineJoin lineJoin
Discussion

The default line join style is kCGLineJoinMiter.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

lineWidth

The stroke width to use for the path.

@property CGFloat lineWidth
Discussion

The default value of this property is 0.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MKOverlayPathView.h

miterLimit

The limiting value that helps avoid spikes at junctions between connected line segments.

@property CGFloat miterLimit
Discussion

The miter limit helps you avoid spikes in paths that use the kCGLineJoinMiter join style. If the ratio of the miter length—that is, the diagonal length of the miter join—to the line thickness exceeds the miter limit, the joint is converted to a bevel join. The default miter limit is 10, which results in the conversion of miters whose angle at the joint is less than 11 degrees.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

path

The current path to use when drawing the overlay.

@property CGPathRef path
Discussion

Getting the value of this property causes the path to be created (using the createPath method) if it does not already exist. You can also assign a path object to this property explicitly.

When assigning a new path object to this property, the receiver retains the path you specify.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

strokeColor

The stroke color to use for the path.

@property (retain) UIColor *strokeColor
Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MKOverlayPathView.h

Instance Methods

applyFillPropertiesToContext:atZoomScale:

Applies the receiver’s current fill-related drawing properties to the specified graphics context

- (void)applyFillPropertiesToContext:(CGContextRef)context atZoomScale:(MKZoomScale)zoomScale
Parameters
context

The graphics context used to draw the view’s contents.

zoomScale

The current zoom scale used for drawing.

Discussion

This is a convenience method for applying all of the drawing properties used when filling a path. This method applies the current fill color to the specified graphics context.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

applyStrokePropertiesToContext:atZoomScale:

Applies the receiver’s current stroke-related drawing properties to the specified graphics context.

- (void)applyStrokePropertiesToContext:(CGContextRef)context atZoomScale:(MKZoomScale)zoomScale
Parameters
context

The graphics context used to draw the view’s contents.

zoomScale

The current zoom scale used for drawing.

Discussion

This is a convenience method for applying all of the drawing properties used when stroking a path. This method applies the stroke color, line width, line join, line cap, miter limit, line dash phase, and line dash attributes to the specified graphics context. This method applies the scale factor in the zoomScale parameter to the line width and line dash pattern automatically so that lines scale appropriately.

This method does not save the current graphics state before applying the new attributes. You must save it yourself and restore it later when you are done drawing.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

createPath

Creates the path for the overlay.

- (void)createPath
Discussion

The default implementation of this method does nothing. Subclasses should override it and use it to create the CGPathRef data type to be used for drawing. After creating the path, your implementation should then assign it to the path property.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

fillPath:inContext:

Fills the area enclosed by the specified path.

- (void)fillPath:(CGPathRef)path inContext:(CGContextRef)context
Parameters
path

The path to fill.

context

The graphics context in which to draw the path.

Discussion

You must set the current fill color before calling this method. Typically you do this by calling the applyFillPropertiesToContext:atZoomScale: method prior to drawing. If the fillColor property is currently nil, this method does nothing.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

invalidatePath

Releases the path associated with the receiver.

- (void)invalidatePath
Discussion

You can call this method at any time where a change in the path information would require you to recreate the path. This method sets the path property to nil, which causes the cached path to be released.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

strokePath:inContext:

Draws a line along the specified path.

- (void)strokePath:(CGPathRef)path inContext:(CGContextRef)context
Parameters
path

The path to draw.

context

The graphics context in which to draw the path.

Discussion

You must set the current stroke color before calling this method. Typically you do this by calling the applyStrokePropertiesToContext:atZoomScale: method prior to drawing. If the strokeColor property is currently nil, this method does nothing.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKOverlayPathView.h

Did this document help you? Yes It's good, but... Not helpful...