Modify the view of the user's current location in mkmapview to the ui you need.
The effect is as follows:
The Code is as follows:
Source code here. Copy all. If some methods are missing (for image processing functions, leave a message)
-(MKAnnotationView *) mapView :( MKMapView *) mapView viewForAnnotation :( id <MKAnnotation>) annotation
{
If ([annotation isKindOfClass: [MKUserLocation class])
{
Static NSString * annotation_id = @ "annotation_id ";
MKPinAnnotationView * pinView = (MKPinAnnotationView *) [map_view dequeueReusableAnnotationViewWithIdentifier: annotation_id];
If (! PinView)
{
MKAnnotationView * annotationView = [[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: annotation_id] autorelease];
AnnotationView. canShowCallout = YES;
// Modify the blue image of the map @ "flag.png"
UIImage * annotation_image = [UIImage imageNamed: @ "flag.png"];
CGRect resizeRect;
ResizeRect. size = annotation_image.size;
CGSize maxSize = CGRectInset (map_view.bounds, 0.0, 0.0). size;
// This segment is used to process images, which can be omitted. The purpose here is to fear that the image is too large.
If (resizeRect. size. width> maxSize. width)
{
ResizeRect. size = CGSizeMake (maxSize. width, resizeRect. size. height/resizeRect. size. width * maxSize. width );
}
If (resizeRect. size. height> maxSize. height)
{
ResizeRect. size = CGSizeMake (resizeRect. size. width/resizeRect. size. height * maxSize. height, maxSize. height );
}
ResizeRect. origin = (CGPoint) {0.0f, 0.0f };
UIGraphicsBeginImageContext (resizeRect. size );
// If your image is of the proper size, you do not need to process it. Simply use your image.
UIImage * resize_image = [annotation_image imageByScalingAndCroppingForSize: CGSizeMake (45, 45)];
CGRect rect = CGRectMake (0.0, 0.0, 45, 45 );
[Resize_image drawInRect: rect];
UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext ();
UIGraphicsEndImageContext ();
AnnotationView. image = resizedImage;
AnnotationView. opaque = NO;
Return annotationView;
}
Else
{
PinView. annotation = annotation;
}
Return pinView;
}
Return nil;
}
From cloud huaikong-abel