2

On the callout bubble on the iPhone SDK's map, can the font be changed for the title and subtitle properties.

I am displeased with the default font shown in the callout bubble, and would like to go with a different font face to match the rest of my application. However, I have not seen much mention of this, which has me concerned that it might not be possible.

I have seen the Building Custom Map Annotation Callouts tutorial, and I guess that would work. But, if at all possible I was hoping that the ability to change a font was built into the MKAnnotationView much the same way I can change the font of a UILabel without subclassing it.

petert
  • 6,672
  • 3
  • 38
  • 46
Jason Whitehorn
  • 13,585
  • 9
  • 54
  • 68
  • Pretty sure you're need to return a custom view, like in the tutorial you linked to. You might start by subclassing `MKAnnotationView`? http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html – petert Mar 16 '11 at 16:41

2 Answers2

2

Subclass the MKAnnotationView then put the category below on top of its implementation:

@implementation UIFont (SytemFontOverride)

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

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize {

    return [UIFont fontWithName:@"Your-Font-Here" size:fontSize];
}

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize {

    return [UIFont fontWithName:@"Your-Font-Here" size:fontSize];
}

#pragma clang diagnostic pop

@end
Sandro Vezzali
  • 147
  • 2
  • 4
0

You will need to use MKAnnotationView, or subclass it, to change the appearance of the title and subtitle labels as you suggest. If you want to create more re-usable code, I'd subclass and add say properties to query and set the UIFont values to your UILabel instances.

petert
  • 6,672
  • 3
  • 38
  • 46
  • 5
    Am I missing something? I don't see any UILabel properties available to configure on an `MKAnnotationView` object. Docs: https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html In my subclass's `initWithAnnotation` method I have `self.image = [UIImage imageNamed:@"custom-map-marker"];`, that works great. I'd like to be able to set properties on a `title` and `subtitle` UILabel property as well... Please advise! – John Erck Nov 08 '13 at 18:06
  • Also can't see how to change those properties in MKAnnotationView. Adding a custom callout view seems to be the only way. – Toydor Jul 21 '14 at 14:21