Mat*_*att 2 iphone annotations mkmapview ios
我的应用程序中有三个注释数组,foodannotations,gasannotations和shoppingnotnotations.我希望每个注释数组都显示不同颜色的引脚.我目前正在使用
- (MKAnnotationView *)mapView:(MKMapView *)sheratonmap viewForAnnotation:(id<MKAnnotation>)annotation {
NSLog(@"Welcome to the Map View Annotation");
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"Annotation Identifier";
MKPinAnnotationView* pinview = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinview.animatesDrop=YES;
pinview.canShowCallout=YES;
pinview.pinColor=MKPinAnnotationColorPurple;
UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightbutton setTitle:annotation.title forState:UIControlStateNormal];
[rightbutton addTarget:self action:@selector(showDetails) forControlEvents:UIControlEventTouchUpInside];
pinview.rightCalloutAccessoryView = rightbutton;
return pinview;
}
Run Code Online (Sandbox Code Playgroud)
如何将其设置为为每个注释数组使用三种不同的引脚颜色.
谢谢!
小智 6
您是否定义了一个实现MKAnnotation
协议的自定义类,在该协议中添加了一些属性来标识它是什么类型的注释?或者您是否定义了三个单独的类(每种类型的注释一个)实现MKAnnotation
?
假设您已经定义了一个注释类,其中您的注释类中有一个int
名为say 的属性annotationType
,那么您可以在viewForAnnotation
以下位置执行此操作:
int annType = ((YourAnnotationClass *)annotation).annotationType;
switch (annType)
{
case 0 : //Food
pinview.pinColor = MKPinAnnotationColorRed;
case 1 : //Gas
pinview.pinColor = MKPinAnnotationColorGreen;
default : //default or Shopping
pinview.pinColor = MKPinAnnotationColorPurple;
}
Run Code Online (Sandbox Code Playgroud)
其他几件事:
dequeueReusableAnnotationViewWithIdentifier:
方法calloutAccessoryControlTapped
.在该委托方法中,您可以使用访问注释view.annotation
. 归档时间: |
|
查看次数: |
2822 次 |
最近记录: |