Daniel Fernandez Daniel Fernandez - 5 months ago 51
iOS Question

Resize UIImageView for leftCalloutAccessoryView in Map Pin Xcode

I am developing and app in Xcode (objective-c) and I have a problem. I have set a leftCalloutAccessoryView image in my map pins but my problem is that the image size is too big. If it is possible, I want to resize the UUImage without changing the real size of the image, because if I change the size of the image, the image gets worst quality and I can see it pixeled.

This is my viewForAnnotation methof whre I have implemented my leftCalloutAccessoryView:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation) {
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];

pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"pin2@2x.png"];
else {
//[mapView.userLocation setTitle:@"I am here"];

/**Pone una imagen a cada map pin leftimage**/
UIImageView *leftIconView;
leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"80_grados.png"]];

pinView.leftCalloutAccessoryView = leftIconView;
leftIconView.layer.cornerRadius = 6;
leftIconView.clipsToBounds = YES;
leftIconView.layer.borderWidth = 1;

UIButton *pinButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = pinButton;

return pinView;

enter image description here

This is what I want to get without changing the image size because it reduces their quality:
enter image description here

Do you know how can I size my
Thank you very much for your response.


I used sample image to fix your issue .Please use the below code to fit the image into pinview

 UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Bartender"]];
    leftIconView.contentMode = UIViewContentModeScaleAspectFit;
    leftIconView.frame = CGRectMake(5, 5, pinView.frame.size.height- 20, pinView.frame.size.height - 20);
    pinView.leftCalloutAccessoryView = leftIconView;
    leftIconView.layer.cornerRadius = 5;
    leftIconView.clipsToBounds = YES;

And also please find the attached screenshot for reference

enter image description here