我想在viewForAnnotation中显示自定义消息而不是“我的位置”。我该怎么做呢?在mkuserlocation上,如何在viewForAnnotation中显示我自己的自定义消息
感谢 德肖恩
我想在viewForAnnotation中显示自定义消息而不是“我的位置”。我该怎么做呢?在mkuserlocation上,如何在viewForAnnotation中显示我自己的自定义消息
感谢 德肖恩
在你MKMapView
的委托,实施方法mapView:viewForAnnotation
并检查注释是MKUserLocation
类型。如果是,请更改注释的标题和字幕属性。标注将自动提取新值。或者您可以创建一个全新的视图并将其返回到此处。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) {
annotation.title = @"I am here";
return nil;
}
return nil;
}
声明:我还没有测试过这个代码。
它可以通过更新Title
财产MKUserLocation
。
由于MKAnnotation
协议不需要进行Title
属性,铸就注释作为参数传递给MKUserLocation
和设置属性
- (MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) {
[(MKUserLocation*)annotation setTitle: @"I am here"];
return nil;
}
return nil;
}
只需直接引用它也能工作,像这样...
mapView.userLocation.title = @"I am here";
这可以在任何地方对地图视图进行引用。
嗨,你不能像这样直接设置标题......是否有任何其他方式来设置此注释的标题? – user605957