2011-12-19 128 views

回答

1

你可能添加的蓝色按钮,这样的事情

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
MKPinAnnotationView *annView=(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annViewIdentifier"]; 

    if (annView == nil) { 
     annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annViewIdentifier"] autorelease]; 
    } 
UIButton *infoDefaultButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

     [infoDefaultButton addTarget:self 
         action:@selector(showDetails:) 
      forControlEvents:UIControlEventTouchUpInside]; 
     annView.rightCalloutAccessoryView = infoDefaultButton; 

} 

,如果你想要的任何自定义按钮,那么你可以添加UIButtonTypeCustom代替UIButtonTypeDetailDisclosure并设置其框架。

+0

annView.image = [UIImage imageNamed:@“flag.png”]; \t \t annView.annotation = annotation; UIButton * rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; \t NSInteger annotationValue = [self.annobjs indexOfObject:annotation]; rightButton.frame = CGRectMake(5,100,10,10); rightButton.tag = annotationValue; UIImage * greyImage = [UIImage imageNamed:@“arrow.png”]; [rightButton setBackgroundImage:grayImage forState:UIControlStateHighlighted]; [rightButton addTarget:self action:@selector(showDetails:)forControlEvents:UIControlEventTouchUpInside]; annView.rightCalloutAccessoryView = rightButton; – 2011-12-19 06:58:56

+0

好的... CGRectMake(0,0,23,23);这是工作,但图像不显示在第一位。剩下的东西? – 2011-12-19 07:11:17

+0

我刚刚做了像你说的,但我的按钮图像不显示。它只有在点击那个按钮的地方后才会显示。在弹出标题和子标题只能看到......有什么可以解决这个问题? – 2011-12-20 13:43:26