如何更改标记图标? [英] How to change marker icon?

查看:93
本文介绍了如何更改标记图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法更改那些用作标记的红色针脚.如果有办法,该怎么办?

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

  1. MKPinAnnotationColorGreen;
  2. MKPinAnnotationColorPurple
  3. MKPinAnnotationColorRed
  1. MKPinAnnotationColorGreen;
  2. MKPinAnnotationColorPurple
  3. 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;
}

这篇关于如何更改标记图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆