Внесите метод делегата viewForAnnotation
для этого.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[yourAnnotationLocation class]])
{
MKAnnotationView *annotationView = (MKAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
//if you need image you can set it like
//annotationView.image = [UIImage imageNamed:@"yourImage.png"];//here we use a nice image instead of the default pins
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
else
{
annotationView.annotation = annotation;
}
if ([annotation.title isEqualToString:@"Midhun"])
{
annotationView.pinColor = MKPinAnnotationColorGreen;
}
else
{
annotationView.pinColor = MKPinAnnotationColorRed;
}
return annotationView;
}
return nil;
}
Для настройки пользовательского свойства в аннотации добавить класс, который подтверждает MKAnnotation
протокола.
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyLocation : NSObject <MKAnnotation> {
NSString *_name;
NSString *_address;
int _yourValue;
CLLocationCoordinate2D _coordinate;
}
@property (copy) NSString *name;
@property (copy) NSString *address;
@property (assign) yourValue;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate;
@end
Это хороший tutorial.
Попробуйте это, annotation1.subtitle = @ "1 аннотацию"; annotation2.subtitle = @ "2-я аннотация"; annotation3.subtitle = @ "3-я аннотация"; Проверить аннотацию если ([annotation.subtitle isEqualToString: @ "1 аннотацию"]) { // Изменение цвета } еще если ([annotation.subtitle isEqualToString: @ "2ст аннотацию"]) { // изменение цвета } еще если ([annotation.subtitle isEqualToString: @ «3ST аннотации»]) { // изменение цвета } – Kalpesh