I was wonderring if there is a way to change those red pins that are used as markers. And if there is a way, how to do it?
Asked
Active
Viewed 4,348 times
3
-
Do you mean the red Badges used for such things as local and push notifications? – Popeye Dec 07 '12 at 11:10
-
1Or do you mean the red pins shown in the map? http://stackoverflow.com/questions/3192650/how-to-change-color-of-pin-for-mapview-iphone – Ramaraj T Dec 07 '12 at 11:14
-
i mean red pins shown on map. – gabrjan Dec 07 '12 at 11:15
1 Answers
6
you can use 3 types of color pins in mapView are bellow..
MKPinAnnotationColorGreen;
MKPinAnnotationColorPurple
MKPinAnnotationColorRed
and if you want to add customview or image then you can add with programatically
also you can change pin in delegate method of MKMapView
like bellow..
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
if (annotation == _mapView.userLocation)
{
// pinView.pinColor = MKPinAnnotationColorRed;
// return pinView;
return nil;
}
pinView.pinColor = MKPinAnnotationColorGreen; // you can use MKPinAnnotationColorPurple, MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
return pinView;
}
and for custom image or pin, use bellow code..
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"yourImageName"];//add any image which you want to show on map instead of red pins
annotationView.annotation = annotation;
return annotationView;
}

Paras Joshi
- 20,427
- 11
- 57
- 70
-
@gabrjan see the updated answer dude.. its simple that you can add image instead of red pins on mapview.. :) – Paras Joshi Dec 07 '12 at 12:16