iphone - MKPinAnnotationView:是否有超过三种颜色可用?

标签 iphone cocoa-touch mapkit mkpinannotationview

根据 Apple 文档,MKPinAnnotationView 的图钉颜色有红色、绿色和紫色。还有什么办法可以得到其他颜色吗?我在文档中没有找到任何内容。

最佳答案

更多;)

alt text enter image description here enter image description here

alt text enter image description here enter image description here

还有原来的:

alt text alt text enter image description here

alt text alt text enter image description here

alt text alt text enter image description here

代码:

- (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView* anView =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"test"];
anView.pinColor=MKPinAnnotationColorPurple;
UIImage* image = nil;
// 2.0 is for retina. Use 3.0 for iPhone6+, 1.0 for "classic" res.
UIGraphicsBeginImageContextWithOptions(anView.frame.size, NO, 2.0);
[anView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData* imgData = UIImagePNGRepresentation(image);
NSString* targetPath = [NSString stringWithFormat:@"%@/%@", [self writablePath], @"thisismypin.png" ];
[imgData writeToFile:targetPath atomically:YES]; 
return anView;
}

-(NSString*) writablePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}

关于iphone - MKPinAnnotationView:是否有超过三种颜色可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1185611/

相关文章:

ios - 如何删除 iOS 7 中的分隔线?

iphone - MapKit - didUpdateToLocation 已调用但 userLocation 未更新

iphone - CoreFoundation 中的 CFStringGetLength 导致 iOS 崩溃

iphone - 用户点击谷歌地图 ios 时如何读取经度和纬度?

javascript - iPhone 中的网页不显示任何内容

ios - TeenSafe iOS 应用程序如何访问短信?

ios - 在 Iphone 中,在哪里存储大量但临时的数据,如 1000 张图像

iphone - 如何让我的 iPhone 应用程序找到我的图像?

javascript - Google map 的标记在 iPhone/iPad 上不显示 InfoBubble

ios - Objective-C GET 请求 - 如何不卡住 UI 并等待响应?