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
In iOS 8
-(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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With