Each image for left callout view

56 views Asked by At

I want leftCalloutAccessoryView have a location's own image, I know how to make a leftCalloutAccessoryView on callout bubble, however I couldn't get the image path

location information is init form a SpotAnnotation class, like bellow

- (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; }

In ViewController works like this

- (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"]];  }

biggest question is here -> initWithImage:

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

There are 1 answers

0
Zoe On

ummm... I solved it..

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

problem is initWithImage:((SpotAnnotation *)annotation).image

I will try hard to get it understand!