2011-12-19 83 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