To set a custom pin

Source: Internet
Author: User

#import <MapKit/MapKit.h>

#import "MyPointAnnotation.h"//import a custom Pin

@interface Myannotationview:mkpinannotationview {

Mypointannotation *mypointannotation;

}

@end

#import "MyAnnotationView.h"

@implementation Myannotationview

-(Instancetype) Initwithannotation: (id<mkannotation>) annotation reuseidentifier: (NSString *) reuseIdentifier {

if (self = [super Initwithannotation:annotation Reuseidentifier:reuseidentifier]) {

Save parameters-pass over the pin

mypointannotation = annotation;

Create a picture

UIImage *image = [UIImage imagenamed:@ "Pink"];

This method is only suitable for static pictures, not suitable for dynamic and drag dynamic functions, they have conflicting

This way inherits Mkannotationview otherwise no effect

NSData *imagedata = uiimagepngrepresentation (image);

Processing ImageData ratio 5

Image = [UIImage imagewithdata:imagedata scale:5];

Modify the size of the current view

Self.frame = CGRectMake (0, 0, 40, 40);

Set up a picture

Self.image = image;

Set fill mode to fill proportionally

Self.contentmode = Uiviewcontentmodescaletofill;

Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (-15,-5, 45, 45)];

Imageview.image = image;

[Self addsubview:imageview];

Allow Bubbles to pop up

Self.canshowcallout = YES;

Dragging

self.draggable = YES;

Drop animation

Self.animatesdrop = YES;

UIButton *leftbutton = [UIButton Buttonwithtype:uibuttontypeinfodark];

[LeftButton addtarget:self Action: @selector (LeftButton) forcontrolevents:uicontroleventtouchupinside];

Set left Access view

Self.leftcalloutaccessoryview = LeftButton;

UIButton *rightbutton = [UIButton buttonwithtype:uibuttontypecontactadd];

[Rightbutton addtarget:self Action: @selector (Rightbutton) forcontrolevents:uicontroleventtouchupinside];

Set Right Access view

Self.rightcalloutaccessoryview = Rightbutton;

}

return self;

}

-(void) LeftButton {

NSLog (@ "leftbutton:%@", mypointannotation.title);

}

-(void) Rightbutton {

NSLog (@ "rightbutton:%@", mypointannotation.information);

}

To set 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.