Search code examples
iosobjective-cuilabelmapkitmkannotation

Change Font of MapKit Annotation Callout Title and Subtitle


I have an MKPointAnnotation being added as an annotation to my MKMapView. I can set its title and subtitle properties but not the font for these properties' corresponding labels. Is there any way to do this without creating a custom view and adding it in didSelectAnnotationView? I've tried overriding systemFontOfSize of methods like below, but there's no reliable way to tell if I'm setting the font of the title or subtitle label.

@implementation UIFont (SytemFontOverride)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize
{
    return [UIFont fontWithName:@"HelveticaNeue" size:20.0];
}

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize
{
    return [UIFont fontWithName:@"HelveticaNeue" size:15.0];
}

#pragma clang diagnostic pop

@end

Solution

  • You are right that override the UIFont class methods isn't a guarantee that you'll intercept font queries for the map callout, too.

    I would recommend checking out the SMCalloutView project for an open source & customizable clone:

    https://github.com/nfarina/calloutview