2012-09-25 58 views
0

G'day全部,iOS更改引脚注释的颜色

我正在尝试更改MKPointAnnotations中引脚的颜色。我试图遵循的大多数代码示例太复杂,我不能遵循。我想出了这个:

// 
// ViewController.m 
// PlayingWithMaps 
// 
// Created by custom on 22/09/12. 
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. 
// 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotationPoint 
{ 
static NSString *annotationIdentifier = @"annotationIdentifier"; 

MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotationPoint reuseIdentifier:annotationIdentifier]; 

pinView.pinColor = MKPinAnnotationColorPurple; 

return pinView; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

// First, choose what type of map 
//mapView.mapType = MKMapTypeHybrid; 
mapView.mapType = MKMapTypeStandard; 


// Second, where is the centre of the map 
CLLocationCoordinate2D centreCoord = {.latitude = -37.123456, .longitude = 145.123456}; 
MKCoordinateSpan mapSpan = {.latitudeDelta = 0.001, .longitudeDelta = 0.001}; 
MKCoordinateRegion region = {centreCoord, mapSpan}; 

[mapView setRegion:region]; 

// Now lets make a single annotation. 
CLLocationCoordinate2D annotationCoordinate; 

annotationCoordinate.latitude = -37.781650; 
annotationCoordinate.longitude = 145.076116; 

MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init]; 
annotationPoint.coordinate = annotationCoordinate; 
annotationPoint.title = @"My point of interest"; 
annotationPoint.subtitle = @"Location"; 

[mapView addAnnotation:annotationPoint]; 

// Read a set of points from files into arrays 
NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"latitudes" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil]; 
NSMutableArray *latitudeStringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByString:@"\n"]]; 

fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"longitudes" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil]; 
NSMutableArray *longitudeStringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByString:@"\n"]]; 

// Now lets put them onto the map 
int i; // Loop control 
for (i=0; i<25; i++) 
{ 
    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init]; 
    annotationCoordinate.latitude = [[latitudeStringsArray objectAtIndex:i]floatValue]; 
    annotationCoordinate.longitude = [[longitudeStringsArray objectAtIndex:i]floatValue]; 
    annotationPoint.coordinate = annotationCoordinate; 
    annotationPoint.title = [NSString stringWithFormat:@"Point %d",i]; 
    annotationPoint.subtitle = [NSString stringWithFormat:@"%f, %f",[[latitudeStringsArray objectAtIndex:i]floatValue],[[longitudeStringsArray objectAtIndex:i]floatValue]]; 
    [mapView addAnnotation:annotationPoint]; 
} 

} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return YES; 
} 

@end 

点出现在正确的地方,但他们是默认的红色,而不是我想要实现的紫色。我从阅读中得到的理解是,无论何时创建注释点,都应该调用(MKAnnotationView)方法,但不会发生。

我知道这是我失踪的根本,但我不知道是什么。

非常感谢所有帮助。

干杯,

回答

2

如果它不叫那么你有没有设置你的ViewController作为委托地图视图。

+0

好的......我该怎么做?谢谢。 –

+0

我刚刚在界面生成器中尝试过,并设法使其工作。感谢您的洞察力。一个。 –

相关问题