Mkmapview a custom Pin

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.