我是 iphone 开发的新手,我正在尝试将自定义按钮添加到注释标注中。我向 rightCalloutAccessoryView 添加常规按钮没有问题,但它不适用于自定义样式。我的图像大小是 32 x 32。我还想在此 stackoverflow 问题之后添加一个自定义地图图钉,非常感谢任何帮助。
我的代码
-(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;
}