自定义地图注释[重复](customize the map annotation [duplicate])

编程入门 行业动态 更新时间:2024-10-17 13:33:14
自定义地图注释[重复](customize the map annotation [duplicate])

这个问题在这里已有答案:

MKMapView:自定义视图 3 代替注释引脚

您好我想在我的观点中添加一个带有数字的动态显示。

如图所示,我已经在地图上显示了图标。

添加数字?

This question already has an answer here:

MKMapView: Instead of Annotation Pin, a custom view 3 answers

Hello I would like to add a dynamic display with a number in my point.

As in the picture, I already have the icons on the map.

Adding the numbers in point?

最满意答案

有一种方法可以定义注释视图的外观:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *pinView = nil; if(annotation != mapView.userLocation) { pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinID"]; if ( pinView == nil ) { pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; } pinView.canShowCallout = YES; pinView.animatesDrop = YES; . . . // ----------------------------------- // Add extra subviews here // ----------------------------------- UILabel *lblNumbers = [[UILabel alloc] init...]; lblNumbers.text = ....; lblNumbers.backgroundColor = [UIColor colorWithRed:0.1 Green:0.1 Blue:0.1]; // add the subview to the pinView [pinView addSubview:lblNumbers]; } return pinView; }

There's a method to define what the annotation view looks like:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *pinView = nil; if(annotation != mapView.userLocation) { pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinID"]; if ( pinView == nil ) { pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; } pinView.canShowCallout = YES; pinView.animatesDrop = YES; . . . // ----------------------------------- // Add extra subviews here // ----------------------------------- UILabel *lblNumbers = [[UILabel alloc] init...]; lblNumbers.text = ....; lblNumbers.backgroundColor = [UIColor colorWithRed:0.1 Green:0.1 Blue:0.1]; // add the subview to the pinView [pinView addSubview:lblNumbers]; } return pinView; }

更多推荐

本文发布于:2023-04-28 02:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   注释   地图   customize   annotation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!