Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView as callout's leftCalloutAccessoryView automatically shifts top-left corner

It works great on iOS 7 but UIImageView's position shifts on iO8 like images below. Also rightCalloutAccessoryView position shifts top-right corner.

Can anybody help?

Cheers.

In iOS 7

iOS 7

In iOS 8

iOS8

-(void)mapView:(MKMapView*)mapView didSelectAnnotationView:(MKAnnotationView*)view {

if(![view.annotation isKindOfClass:[MKUserLocation class]]) {

    UBAnnotation *selectedAnnotation = view.annotation;

    NSURL * imageUrlAtIndex = [NSURL URLWithString:[[self.objects objectAtIndex:selectedAnnotation.idx] ad_thumbImageUrl]];


    UIImageView * leftCalloutView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 40, 40)];
    [leftCalloutView setImageWithURL:imageUrlAtIndex];
    leftCalloutView.layer.masksToBounds = YES;
    leftCalloutView.layer.cornerRadius = 6;

    view.leftCalloutAccessoryView = leftCalloutView;

}

}

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) annotation {

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

if ([annotation isKindOfClass:[MKUserLocation class]]) {
    return nil;
} else {
    annView.image = [UIImage imageNamed:@"pin"];

    annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annView.rightCalloutAccessoryView.tintColor = [UBColor ubGreenColor];
    annView.animatesDrop= NO;
    annView.canShowCallout = YES;

}

return annView;

}

like image 977
Gokhan Gultekin Avatar asked Sep 21 '14 10:09

Gokhan Gultekin


1 Answers

I solved it!

It's all about titleLabel's string length. If the string length over 20-25 character, left and right accessory view shifts up.

First, I trimmed the string that shown on title label or subtitle label. After, concatenate "..." as string at the end of the string.

Solution is a little bit hack, but it works like charm.

like image 107
Gokhan Gultekin Avatar answered Sep 28 '22 13:09

Gokhan Gultekin