我最近遇到了this website,我一直試圖添加到我的電話中查看按鈕(從圖像)。將附件視圖按鈕添加到MKMapView調用註釋?
網站示例上的代碼工作得很好,但是當我試圖將相同的代碼添加到我的項目中時,我得不到相同的結果。
顯然有一些我錯過了,但我似乎無法工作這一個!
這裏是我的代碼爲註解:
- (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;
}
任何幫助,將不勝感激! :)
不幸的是,你提供的鏈接是死的 – 2016-10-14 20:59:09