自定义地图注释[重复](customize the map annotation [duplicate])
这个问题在这里已有答案:
MKMapView:自定义视图 3 代替注释引脚您好我想在我的观点中添加一个带有数字的动态显示。
如图所示,我已经在地图上显示了图标。
添加数字?
This question already has an answer here:
MKMapView: Instead of Annotation Pin, a custom view 3 answersHello 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; }更多推荐
发布评论