如何将框架设置为在MapAnnotation上设置的UIImage

时间:2013-10-23 12:51:54

标签: ios map

我需要将帧设置为一个图像,该图像用作pinAnnotation的图像。

这是我添加图片

MKAnnotationView* annotationView = [objMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    if(!annotationView)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                      reuseIdentifier:annotationIdentifier];
    }

    annotationView.image = [UIImage imageNamed:@"rrb.png"] ;

enter image description here

当前视图是这样的...而此图像将用于每个注释。 虽然这个图像很大,但我如何设置框架,使其适合我的框架。 这些图像将通过webService传播。

视图应该是这样的...(我改变了图像的大小)

enter image description here

enter image description here

在注释上设置图像:

UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:joinString]];
        [imgV setFrame:CGRectMake(0, 0, 40, 40)];
         annotationView.image = imgV.image;

// join String是包含从webService获取的图像的字符串。

2 个答案:

答案 0 :(得分:0)

mapView delegate有一个名为viewForAnnotation的方法。您应该能够通过访问注释视图并将其更改为您喜欢的任何内容来设置注释视图的框架。

答案 1 :(得分:0)

您可以使用以下内容:

  • (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

    MKAnnotationView * annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

    UIImage * image = [UIImage imageNamed:@“image.png”]; UIImageView * imageView = [[UIImageView alloc] initWithImage:image]; [annView addSubview:imageView]; [imageView发布];

    MKPinAnnotationView * pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

    [annView addSubview:pinView]; [pinView发布];

    返回annView; }