2011-03-16 12 views
2

在iPhone SDK的地图上的标注气泡上,可以更改标题和字幕属性的字体。MKAnnotationView的不同字体

我对标注气泡中显示的默认字体感到不满,并希望使用不同的字体来匹配我的应用程序的其余部分。但是,我没有看到太多这方面的内容,我担心这可能是不可能的。

我见过Building Custom Map Annotation Callouts教程,我猜这会起作用。但是,如果可能的话,我希望改变字体的能力已经被嵌入到MKAnnotationView中,就像我可以改变UILabel的字体而不用创建子类一样。

+0

很肯定你需要在你链接到教程返回一个自定义视图,等等。你可以从“MKAnnotationView”的子类开始? http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html – petert 2011-03-16 16:41:16

回答

0

您将需要使用MKAnnotationView或其子类来更改标题和字幕标签的外观。如果你想创建更多的可重复使用的代码,我会继承并添加say属性来查询,并将UIFont值设置为UILabel实例。

+3

我错过了什么吗?我没有看到任何UILabel属性可以在'MKAnnotationView'对象上配置。 Docs:https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html在我的子类的'initWithAnnotation'方法中,我有'self.image = [UIImage imageNamed:@“custom -map-marker“];',这很好。我希望能够在'title'和'subtitle' UILabel属性上设置属性以及...请指教! – 2013-11-08 18:06:06

+0

也看不到如何在MKAnnotationView中更改这些属性。添加自定义标注视图似乎是唯一的方法。 – Toydor 2014-07-21 14:21:17

2

子类MKAnnotationView然后把以下分类关于其实施的顶部:

@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 
+1

为注解视图创建子类是不必要的,这个方法仍然可以工作 – 2014-06-02 10:21:58

+0

在Swift中这么做简单吗? – TimWhiting 2015-01-21 21:51:26

+0

这对Apple审批流程没有任何问题吗? – 2015-06-25 09:35:55