How to customize a pin
--Set the agent for Mkmapview
Implement the following proxy method, which returns the Pin control
-(Mkannotationview *) Mapview: ( Mkmapview *) Mapview viewforannotation: (id< mkannotation >) annotation;
Create and return the corresponding PIN control based on the passed in (ID < mkannotation >) annotation parameter
Use of Proxy methods note
If nil is returned, the displayed pin takes the system's default style
A blue glowing dot that identifies the user's location, which is also a pin, and when the pin is displayed, the proxy method is also called
Therefore, you need to be clear in the Proxy method (ID < mkannotation >) annotation parameter represents a custom pin or a blue glow dot
1-(Mkannotationview *) Mapview: (Mkmapview *) Mapview viewforannotation: (id<mkannotation>) annotation2 {3//Determine the type of annotation4if (![ Annotation Iskindofclass:[mjtuangouannotationClass]])return nil;56//Create Mkannotationview7static NSString *id =@"Tuangou ";8 Mkannotationview *annoview = [Mapview dequeuereusableannotationviewwithidentifier:id];9 if (Annoview = = nil) {Annoview = [[Mkannotationview alloc] Initwithannotation:annotation reuseidentifier : ID]; One annoview.canshowcallout = YES; 12} // transfer model data annoview.annotation = annotation; mjtuangouannotation// set image ( *tuangouannotation = annotation; Annoview.image = [UIImage ImageNamed:tuangouAnnotation.icon]; return annoview; +} Mkannotationview
The pin control on the map is Mkannotationview
Properties of the Mkannotationview
1@property (nonatomic, strong) id <MKAnnotation> annotation;2 PIN Model34 @property (nonatomic, strong) UIImage *image; Span class= "number" >5 the picture displayed 6 7 @property ( nonatomic) BOOL canshowcallout; 8 whether the callout is displayed 9 10 @property ( nonatomic) Cgpoint Calloutoffset; 11 the offset of the callout 12 13 @property ( Strong, Nonatomic) UIView *rightcalloutaccessoryview; 14 the callout to the right shows what controls 15 16 @property (strong, Nonatomic) UIView *leftcalloutaccessoryview; 17 What controls appear to the left of the callout
Mkpinannotationview
Mkpinannotationview is a subclass of Mkannotationview
Mkpinannotationview has 2 more properties than Mkannotationview
Mkpinannotationcolor pincolor;// pin color BOOL animatesdrop;// pin When the first time it appears from the sky
Mkmapview a custom Pin