【问题标题】:How can I customize the title/subtitle font in callout from MKAnnotationView or just hide them?如何在 MKAnnotationView 的标注中自定义标题/副标题字体或隐藏它们?
【发布时间】:2016-02-24 03:33:06
【问题描述】:
我有一个 calloutDetail 的视图:
annotationView.detailCalloutAccessoryView = mapInformationView.view
它工作得很好,但我不想显示标题/副标题,只是我的自定义视图。但是当我将标题/副标题留空时,不会显示标注。
那么,我该如何隐藏它们或只是更改它们的字体大小和名称?
【问题讨论】:
标签:
swift
mapkit
title
mkannotation
callout
【解决方案1】:
隐藏标题(或副标题)标签的一种方法是将MKAnnotation 的title(或subtitle)属性设置为nil。
如果您希望标题显示在标记上,而不是标注上,请切换 MKAnnotationView 的子类中的 title 值,覆盖 setSelected(_:animated:)。
override func setSelected(_ selected: Bool, animated: Bool) {
if selected {
annotation.title = nil
} else {
annotation.title = "Title"
}
super.setSelected(selected, animated: animated)
}