我需要将帧设置为一个图像,该图像用作pinAnnotation的图像。
这是我添加图片
MKAnnotationView* annotationView = [objMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if(!annotationView)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier];
}
annotationView.image = [UIImage imageNamed:@"rrb.png"] ;
当前视图是这样的...而此图像将用于每个注释。 虽然这个图像很大,但我如何设置框架,使其适合我的框架。 这些图像将通过webService传播。
视图应该是这样的...(我改变了图像的大小)
在注释上设置图像:
UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:joinString]];
[imgV setFrame:CGRectMake(0, 0, 40, 40)];
annotationView.image = imgV.image;
// join String是包含从webService获取的图像的字符串。
答案 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; }