iOS更改pin注释的颜色

iOS更改pin注释的颜色,ios,cocoa,mkmapview,mkannotation,mkannotationview,Ios,Cocoa,Mkmapview,Mkannotation,Mkannotationview,一整天 我正试图改变MKPoint注解中针脚的颜色。我尝试遵循的大多数代码示例都太复杂,我无法遵循。我想到了这个: // // ViewController.m // PlayingWithMaps // // Created by custom on 22/09/12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "ViewController.h" @interface View

一整天

我正试图改变MKPoint注解中针脚的颜色。我尝试遵循的大多数代码示例都太复杂,我无法遵循。我想到了这个:

//
//  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
//
//ViewController.m
//玩地图
//
//由自定义于2012年9月22日创建。
//版权所有(c)2012年\uuuu MyCompanyName\uuuuu。版权所有。
//
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图用于注释:(id)注释点
{
静态NSString*annotationIdentifier=@“annotationIdentifier”;
MKPinAnnotationView*pinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotationPoint重用标识符:annotationIdentifier];
pinView.pinColor=MKPinAnnotationColorPurple;
返回pinView;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
//首先,选择什么类型的地图
//mapView.mapType=MKMapTypeHybrid;
mapView.mapType=MKMapTypeStandard;
//第二,地图的中心在哪里
CLLocationCoordinate2D centreCoord={.纬度=-37.123456,.经度=145.123456};
MKCoordinateSpan映射span={.latitudeDelta=0.001,.longitudeDelta=0.001};
MKCoordinateRegion={centreCoord,mapSpan};
[地图视图设置区域:区域];
//现在让我们做一个注释。
CLLocationCoordinate2D注释坐标;
注释坐标纬度=-37.781650;
注释坐标.经度=145.076116;
MKPointAnnotation*annotationPoint=[[MKPointAnnotation alloc]init];
annotationPoint.coordinate=annotationCoordinate;
annotationPoint.title=@“我的兴趣点”;
annotationPoint.subtitle=@“位置”;
[地图视图添加注释:注释点];
//将一组点从文件读入数组
NSString*fileString=[NSString STRINGWITH CONTENTS OFFILE:[[NSBundle mainBundle]pathForResource:@“txt”类型的“纬度”]编码:NSUTF8STRING编码错误:nil];
NSMutableArray*latitudeStringsArray=[NSMutableArray arrayWithArray:[fileString ComponentsParatedByString:@“\n”];
fileString=[NSString stringWithContentsOfFile:[NSBundle mainBundle]pathForResource:@“经度”类型:@“txt”]编码:NSUTF8StringEncoding错误:nil];
NSMutableArray*longitudeStringsArray=[NSMutableArray arrayWithArray:[fileString ComponentsParatedByString:@“\n”];
//现在让我们把它们放到地图上
int i;//循环控制

对于(i=0;i如果未调用它,则您没有将ViewController设置为地图视图的代理。

好的……我该怎么做?谢谢。我刚刚在界面生成器中尝试并设法使其工作。感谢您的深入了解。