我最近遇到过这个网站 http://www.everydayone.com/2009/08/mapkit-annotation-with-buttons-example/我一直在尝试向我的呼出视图添加一个按钮(来自图像)。
网站示例上的代码工作得很好,但是当我尝试将相同的代码添加到我的项目中时,我没有得到相同的结果。
显然我错过了一些东西,但我似乎无法解决这个问题!
这是我的注释代码:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeCustom];
advertButton.frame = CGRectMake(0, 0, 23, 23);
advertButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
advertButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[advertButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
[advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = advertButton;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
任何帮助,将不胜感激! :)
那家伙正在使用自定义图像来模仿细节披露。您实际上可以很容易地获得标准详细信息披露:
[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)