首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在MKMapView中为引脚添加标题?

如何在MKMapView中为引脚添加标题?
EN

Stack Overflow用户
提问于 2011-09-08 16:19:49
回答 6查看 2.4K关注 0票数 3

我有drop pin的代码但我想显示标题栏,如上图所示。如何添加星图和点评图?

EN

回答 6

Stack Overflow用户

发布于 2011-09-08 16:27:13

您可以使用您的自定义MKAnnotationView

票数 0
EN

Stack Overflow用户

发布于 2011-09-08 16:30:29

代码语言:javascript
运行
复制
    - (MKAnnotationView *)mapView:(MKMapView *)mapViewTmp viewForAnnotation:(id<MKAnnotation>)annotation
    {
        if(annotation == mapView.userLocation)
            return nil;
        MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewTmp dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
        if (pinView ==nil) {
            pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"Pin"];
            {

                if([addedAnns containsObject:annotation]){
                    MyAnnotation *a = [addedAnns objectAtIndex:[addedAnns indexOfObject:annotation]];
                    UIImage * image = [UIImage imageNamed:a.pinImage];
                    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
                    imageView.frame=[pinView bounds];
                    [pinView addSubview:imageView];
                    //[imageView release];
                    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDeta`enter code here`ilDisclosure];
                    pinView.rightCalloutAccessoryView.tag = a.iAnnId;
                    [(UIButton *)pinView.rightCalloutAccessoryView addTarget:self action:@selector(openSpot:) forControlEvents:UIControlEventTouchUpInside];


                    pinView.enabled = YES;
                    pinView.centerOffset = CGPointMake(0,-15);
                    pinView.calloutOffset = CGPointMake(-8,0);
                    pinView.canShowCallout = YES;
                }
            }
            pinView.animatesDrop = YES;     
        } 
        return pinView; // we cant release Or Auto release this object. Due To it will use futher
    }





// The left accessory view to be used in the standard callout.
                    @property (retain, nonatomic) UIView *leftCalloutAccessoryView;

                    // The right accessory view to be used in the standard callout.
                    @property (retain, nonatomic) UIView *rightCalloutAccessoryView;

正如您所看到的,我正在向rightCalloutAccessoryView添加按钮。类似地,您可以向其中添加图像。

票数 0
EN

Stack Overflow用户

发布于 2011-09-08 16:32:08

使用此委托方法

代码语言:javascript
运行
复制
 -(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;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7345099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档