4
A
回答
16
可以使用自定义视图每个注释与一个UIView
,一个UIImageView
和一个标签来显示不同的值。这将在方法- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id)newAnnotation
内完成。你必须采取UIView
尺寸的双倍透明颜色相对于UIImageView
更准确地查看放大和缩小mapview。
代码-----
-(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;
}
希望这有助于。
6
- 创建一个自定义的注释类(
MKAnnotation
) - 创建自定义AnnotationView类(
MKAnnotationView
)
确保您在定义标题,背景图像和自定义注释的其他元素AnnotationView
类作为属性。
重写以下方法,并设置您在
AnnotationView
类中定义的属性的值。- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{ if ([<Object of CustomAnnotation class> isKindOfClass:[MKUserLocation class]]) return nil; CustomAnnotation* custom_anno = (CustomAnnotation*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"custom_annotation"]; if (!custom_anno){ custom_anno = [[CustomAnnotation alloc] initWithAnnotation:annotation reuseIdentifier:@"custom_annotation"]; custom_anno.frame = CGRectMake(0, 0, 250, 57.5); custom_anno.canShowCallout = NO;//CHange if you want to change callout behaviour (thats is it's abilty to apper). I set it top no because i did not want a callout. UIImageView* icon = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 40, 40)]; [icon setImageWithURL:<your image> placeholderImage:<your placeholder image>];//placeholder image = nil if you do not want one. icon.backgroundColor = [UIColor lightGrayColor]; UILabel* name = [[UILabel alloc] initWithFrame:CGRectMake(50, 5, 200, 20)]; name.text = nameValue; UILabel* category = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 200, 20)]; category.text = otherValue; [custom_anno addSubview:icon]; [custom_anno addSubview:name]; [custom_anno addSubview:category]; } return custom_anno; }
我的自定义注释类是'Annotation',自定义注释视图类是'CustomAnnotation'。根据您的需求改变。
之后,只需创建一个Annotation
类的对象,并使用它。
编辑:
确保您覆盖follwing方法诠释他的自定义注解视图类:
在.H:
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
中的m:
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
编辑2:
你可以用它在你的视图控制器是这样的:
MKMapView* cellMap = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)];
cellMap.delegate = self;
cellMap.userInteractionEnabled = NO;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(<your coordinates>);
MKCoordinateSpan span = MKCoordinateSpanMake(0.04, 0.04);
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
cellMap.showsUserLocation = NO;
[cellMap setRegion:region animated:YES];
Annotation* anon = [[Annotation alloc] init];
anon.coordinate = center;
[cellMap addAnnotation:anon];
[checkIn addSubview:cellMap];
相关问题
- 1. 如何在iphone应用中的Mapview中添加多个注释
- 2. 如何在iPhone中添加地图视图中心的注释?
- 3. 如何在地图视图中添加注释在Iphone
- 4. 如何在mapview中添加自定义标注视图
- 5. 如何在Struts标签中添加注释?
- 6. 如何在图片上添加标签?
- 7. 在highcharts标签中添加图片
- 8. 在tableView中使用mapView注释
- 9. 如何在mapview中显示pin注释?
- 10. iPhone Mapview update标注视图
- 11. 如何在Swift中使用GPS坐标在地图上添加多个注释?
- 12. 如何在iphone中创建自定义注释和标注
- 13. 在iPhone中的地图中添加路线注释
- 14. 快速使用AlertController在mapView上添加注释
- 15. 如何在注释中使用注释?
- 16. 如何在地图的注释标注中添加自定义视图
- 17. 如何在锚标签的标题属性中添加图片标签?
- 18. 如何在PHP Eclipse中添加注释?
- 19. 如何在Reddit共享中添加图片标签?
- 20. 如何在TVML的img标签中添加占位符图片?
- 21. 如何在div中添加滚动图片标签
- 22. 在mapview注释中添加了揭密按钮
- 23. 如何从标签中为属性定义添加注释?
- 24. 想要使用VB.NET在PowerPoint幻灯片中添加注释
- 25. 添加标题,注释和图像
- 26. 在D3和弦图中添加标签
- 27. 如何在iphone中使用mapview?
- 28. 如何使用php在注释中关闭标签
- 29. 在CorePlot中向CandlestickPlot添加多个注释/标签
- 30. 钛 - Mapview和注释
你好你有任何演示请发送给我..我在这么麻烦.. – 2014
谢谢。我解决了我的问题很容易从您的代码谢谢兄弟.. – 2014
什么是存储在alertInfoArray中的数据的格式和我们可以给标记注释的功能 – Rinku