gpt4 book ai didi

ios - 如何在 iPhone 中使用图像和标签在 Mapview 中添加注释?

转载 作者:可可西里 更新时间:2023-11-01 05:01:06 25 4
gpt4 key购买 nike

image1 image here

我在我的 iPhone 应用程序中使用 MKMapview。

如何在 MKMapkit Framework 的注解中赋值?

最佳答案

您可以使用一个 UIView、一个 UIImageView 和一个 Label 为每个注释使用自定义 View 来显示不同的值。这将在方法 - (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation 中完成。相对于 UIImageView,您必须将 UIView 的大小加倍并使用透明颜色,以便在 mapview 中放大和缩小时获得更精确的 View 。

代码-----

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString * const kPinAnnotationIdentifier = @"PinIdentifier";
if(annotation == self._mapView.userLocation)
{
return nil;
}

MyAnnotation *myAnnotation = (MyAnnotation *)annotation;
MKAnnotationView *newAnnotation = (MKAnnotationView*)[self._mapView dequeueReusableAnnotationViewWithIdentifier:kPinAnnotationIdentifier];

if(!newAnnotation){
newAnnotation = [[MKAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:@"userloc"];
}

NSDictionary *dict=[alertInfoArray objectAtIndex:myAnnotation.ann_tag];
UIView *anView=[[UIView alloc] init];
anView.backgroundColor=[UIColor clearColor];

UIImageView *bgImg=[[UIImageView alloc] init];
bgImg.image=[UIImage imageNamed:@""];
bgImg.backgroundColor=[UIColor clearColor];

UIImageView *imgView=[[UIImageView alloc] init];
imgView.tag=myAnnotation.ann_tag;

UILabel *lblName=[[UILabel alloc] init];
lblName.font=[UIFont systemFontOfSize:12];
lblName.textAlignment=UITextAlignmentCenter;
lblName.textColor=[UIColor whiteColor];
lblName.backgroundColor=[UIColor clearColor];
lblName.text=TEXT YOU WANT ;

newAnnotation.frame=CGRectMake(0, 0, 70, 212);
anView.frame=CGRectMake(0, 0, 70, 212);
bgImg.frame=CGRectMake(0, 0, 70, 106);
bgImg.image=[UIImage imageNamed:@"thumb-needhelp.png"];

imgView.frame=CGRectMake(8,25,55,48);
imgView.image=[UIImage imageNamed:@"girl-default.png"];
lblName.frame=CGRectMake(5,79,60,10);



[anView addSubview:bgImg];
[bgImg release];
[anView addSubview:imgView];
[imgView release];
[newAnnotation addSubview:anView];
[anView release];

newAnnotation.canShowCallout=YES;
[newAnnotation setEnabled:YES];

return newAnnotation;
}

希望这对您有所帮助。

关于ios - 如何在 iPhone 中使用图像和标签在 Mapview 中添加注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18457975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com