#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