左侧标注视图的每个图像

时间:2017-06-25 09:02:37

标签: ios objective-c annotations mapkit callout

我想leftCalloutAccessoryView有一个位置自己的图像,我知道如何在callout bubble上创建一个leftCalloutAccessoryView,但是我无法获得图像路径

位置信息是一个SpotAnnotation类的初始化,如下面的

- (id) initWithTitle:(NSString *)aTitle latitude:(CLLocationDegrees)aLat longitude:(CLLocationDegrees)aLon imageName:(UIImage *)imgName{
self.coordinate = CLLocationCoordinate2DMake(aLat, aLon);
self.currentTitle = aTitle;
self.places = [[NSMutableArray alloc] initWithCapacity:0];
self.image = imgName;  
return self; }

在ViewController中像这样工作

- (NSArray *) spots{   
SpotAnnotation *s1 = [[SpotAnnotation alloc] initWithTitle:@"TaipeiZoo" latitude:25.039550 longitude:121.560265 imageName:[UIImage imageNamed:@"taipeiZoo.jpg"]];
SpotAnnotation *s2 = [[SpotAnnotation alloc] initWithTitle:@"Eslite" latitude:25.039720 longitude:121.565874 imageName:[UIImage imageNamed:@"Eslite.jpg"]];  }

最大的问题在这里 - > initWithImage:

 UIImageView *leftIconView = [[UIImageView alloc] initWithImage:"how can I get image path here"];
 leftIconView.frame = CGRectMake(10, 10, 50, 50);
 pin.leftCalloutAccessoryView = leftIconView;

1 个答案:

答案 0 :(得分:0)

嗯......我解决了..

UIImageView *leftIconView = [[UIImageView alloc] initWithImage:((SpotAnnotation *)annotation).image];
        leftIconView.frame = CGRectMake(0, 0, 50, 50);
        leftIconView.contentMode = UIViewContentModeScaleAspectFit;
        pin.leftCalloutAccessoryView = leftIconView;

问题是initWithImage:((SpotAnnotation *)annotation).image

我会努力让它明白!