gpt4 book ai didi

ios - 在 mkMapview 中显示注释的不同图像

转载 作者:行者123 更新时间:2023-11-29 12:48:39 25 4
gpt4 key购买 nike

基于我的不同枚举值,我需要在我的 map View 中显示不同的图像。我该怎么做?我是 iOS 开发的新手。请任何人帮助我。

最佳答案

您需要在 View Controller 中使用“ViewForAnnotation”委托(delegate)方法。

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
if( [annotation isKindOfClass:[Annotation class] ] )
{

static NSString * AnnotationID = @"Annotation";

Annotation * pannotation = (Annotation *)annotation;
//if( pannotation == nil ) return nil;

MKAnnotationView *annotationView = nil;

annotationView = [self.mMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationID];
if( annotationView == nil )
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationID] autorelease];

}


UIImage * flagImage = nil;

if(Your enum Values)
flagImage = [UIImage imageNamed:@"darkgreendot.png"];
else if(....)
flagImage = [UIImage imageNamed:@"orangedot.png"];
else
flagImage = [UIImage imageNamed:@"bluedot.png"];

CGRect resizeRect;
resizeRect.size = flagImage.size;
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[flagImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;

return annotationView;
}
}

希望对您有所帮助。

关于ios - 在 mkMapview 中显示注释的不同图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23009193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com