如何更改标记图标?
问题描述:
我想知道是否有办法更改那些用作标记的红色针脚.如果有办法,该怎么办?
I was wonderring if there is a way to change those red pins that are used as markers. And if there is a way, how to do it?
答
您可以在mapView中使用以下3种颜色的图钉..
you can use 3 types of color pins in mapView are bellow..
-
MKPinAnnotationColorGreen;
-
MKPinAnnotationColorPurple
-
MKPinAnnotationColorRed
-
MKPinAnnotationColorGreen;
MKPinAnnotationColorPurple
MKPinAnnotationColorRed
如果您要添加customview或图片,则可以通过编程方式添加
and if you want to add customview or image then you can add with programatically
还可以像下面这样在MKMapView
的委托方法中更改引脚..
also you can change pin in delegate method of MKMapView
like bellow..
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
if (annotation == _mapView.userLocation)
{
// pinView.pinColor = MKPinAnnotationColorRed;
// return pinView;
return nil;
}
pinView.pinColor = MKPinAnnotationColorGreen; // you can use MKPinAnnotationColorPurple, MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
return pinView;
}
对于自定义图像或图钉,请使用下面的代码.
and for custom image or pin, use bellow code..
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"yourImageName"];//add any image which you want to show on map instead of red pins
annotationView.annotation = annotation;
return annotationView;
}