0

我已经实现了tapOnMarker 选择器,并创建了自定义的annotationView。它显示了annotationView,但是当我点击pinpoint时,annotationView抽象出计数小于当前pinpoint的pinpoint,并且pinpoints有最大计数显示在annotationView上,这是我的实现代码。

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
    frame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbox.png"]];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame =CGRectMake(0, 0,0, 0);
    [button setBackgroundImage:[UIImage imageNamed:@"pinMarker.png"] forState:UIControlStateNormal];
    button.enabled = YES;
    button.userInteractionEnabled = YES;
    [button addTarget:self action:@selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [marker setLabel:frame];
}

4

1 回答 1

1

加载标记时,请执行以下步骤:

RMMarker *marker = [[RMMarker alloc]initWithUIImage:img anchorPoint:CGPointMake(0.5, 1.0)];
[marker setText:@"hello"  forMarker: marker];
[marker hideLabel];

- (void) setText: (NSString*) text forMarker: (RMMarker*) marker
{
  CGSize textSize = [text sizeWithFont: [RMMarker defaultFont]]; 
  CGPoint position = CGPointMake(  -(textSize.width/2 - marker.bounds.size.width/2), 0 );
  [marker changeLabelUsingText: text position: position font: [UIFont systemFontOfSize: 15.0]foregroundColor: [UIColor whiteColor] backgroundColor: [UIColor blackColor]];  
}

并且每当您单击标记时,将调用这些方法并显示标记:

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
  NSArray* markers = [self.markerManager markers];
  for(RMMarker* m in markers) {
    if ([m class] == [RMMarker class])
      [m hideLabel];
  }
  [marker showLabel];   
}
于 2012-08-07T09:27:57.743 回答