Here is a solution that accurately replicates the UIBarButtonItem image, which is otherwise obtained using the UIBarButtonSystemItemAction system UIBarButtonSystemItemAction . For example, a newly created UIButton is inserted into the MKAnnotationView :
Create a category file containing this method:
@implementation UIImage (Custom) + (UIImage *)actionButtonImage { CGRect rect = CGRectMake(0, 0, 20, 27); UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); [[UIColor colorWithRed:3/255.0 green:122/255.0 blue:1 alpha:1] set]; UIBezierPath *path = [UIBezierPath bezierPath];
In the MKMapView MKMapView add this implementation (adapt if necessary):
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Item"]; view.canShowCallout = YES; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *actionImage = [UIImage actionButtonImage]; [button setImage:actionImage forState:UIControlStateNormal]; button.frame = CGRectMake(0, 0, actionImage.size.width, actionImage.size.height); view.leftCalloutAccessoryView = button; return view; }
bio
source share