在mkuserlocation上,如何在viewForAnnotation中显示我自己的自定义消息 [英] On mkuserlocation, how do I show my own custom message in viewForAnnotation

查看:372
本文介绍了在mkuserlocation上,如何在viewForAnnotation中显示我自己的自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在viewForAnnotation中显示自定义消息而不是我的位置。我该怎么做?

I want to show a custom message instead of "My Location" in viewForAnnotation. How do I do this?

谢谢
Deshawn

Thanks Deshawn

推荐答案

MKMapView 的委托中,实现方法 mapView:viewForAnnotation 并检查注释是否为 MKUserLocation 。如果是,请更改注释的标题和副标题属性。标注将自动拉出新值。或者你可以创建一个全新的视图并在这里返回。

In the delegate of your MKMapView, implement the method mapView:viewForAnnotation and check if the annotation is of type MKUserLocation. If yes, change the title and subtitle properties of the annotation. The callout will automatically pull the new values. Or you can create a totally new view and return it here.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        annotation.title = @"I am here";
        return nil;
    }
    return nil;
}

免责声明:我尚未测试此代码。

Disclaimer: I haven't tested this code.

这篇关于在mkuserlocation上,如何在viewForAnnotation中显示我自己的自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆