iphone - 如何在 MKMapView 中为图钉添加标题?

标签 iphone mapkit

enter image description here

我有放置图钉的代码。但我想显示标题栏,如上图所示。如何添加星星图片和评论图片?

最佳答案

使用此委托(delegate)方法

 -(MKAnnotationView*)mapView:(MKMapView)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
      // If you are showing the users location on the map you don't want to change it
      MKAnnotationView *view = nil;
      if (annotation != mapView.userLocation) {
        // This is not the users location indicator (the blue dot)
        view = [mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
        if (!view) {
          // Could not reuse a view ...

          // Creating a new annotation view, in this case it still looks like a pin
          view = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"] autorelease];
          view.canShowCallOut = YES; // So that the callout can appear

          UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someName"]];
          myImageView.frame = CGRectMake(0,0,31,31); // Change the size of the image to fit the callout

          // Change this to rightCallout... to move the image to the right side
          view.leftCalloutAccessoryView = myImageView;
          [myImageView release], myImageView = nil;
        }
      }
      return view;
    }

关于iphone - 如何在 MKMapView 中为图钉添加标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7345099/

相关文章:

iPhone 缩放不会放大菜单按钮中的文本

ios - 如何为 MKPolygonRenderer 提供图像?

ios - 强制 MKMapView 删除 MKOverlayRenderer

objective-c - xcode 有错误线程 1 :Program received signal 'SIGABRT'

c# - Unity3D游戏: deal with constants within one file

iphone - 显示没有动画的 UIKeyboard

iphone - 自定义 UINavigationBar 的最惯用的 iOS5 方式?

iphone - CVOpenGLESTextureCacheCreateTextureFromImage 返回 -6683(kCVReturnPixelBufferNotOpenGLCompatible)

ios - 如何制作自定义图钉并同时使用 FollowWithHeading 模式?

ios - 从底部看 Mapkit 自定义标注幻灯片 View