2013-02-28 58 views
0

我是iphone的开发noob,我试图添加一个自定义按钮到注释标注。添加常规按钮到rightCalloutAccessoryView没有问题,但它不适用于自定义样式。我的图像大小是32 x 32.我也想添加一个自定义地图针在这个计算器问题here任何帮助,非常感谢。如何将自定义按钮/ MapPin添加到MKAnnotation?

MY CODE

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
// Define your reuse identifier. 
static NSString *identifier = @"MapPoint"; 

if ([annotation isKindOfClass:[MapPoint class]]) { 
    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    } else { 
     annotationView.annotation = annotation; 
    } 
    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 
    annotationView.animatesDrop = YES; 
    annotationView.image = [UIImage imageNamed:@"myimage.png"]; 

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    //UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [rightButton setImage:[UIImage imageNamed:@"phony2.png"] forState:UIControlStateNormal]; 
    [rightButton addTarget:self 
        action:@selector(showDetails:) 
      forControlEvents:UIControlEventTouchUpInside]; 
    annotationView.rightCalloutAccessoryView = rightButton; 

    return annotationView; 
} 
return nil;  

}

回答

2
[rightButton addTarget:self 
       action:@selector(showDetails:) 

卸下按钮

[rightButton setFrame:CGRectMake(0,0,32,32)]; 

的这条线 并设置框架,并从打浇口方法中的轻击动作

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; 

您在哪里获得注释视图。

希望这会帮助你。

+1

感谢您的回复。我尝试了你的建议,但我仍然没有任何运气。 – 2013-02-28 13:44:55

+0

@B。钱:你必须更具体一点,“没有任何运气”。 – Craig 2013-03-03 22:46:06

相关问题