【发布时间】:2016-09-13 10:30:51
【问题描述】:
在我的应用程序中,我有以下情况。
我已经使用自定义 detailCalloutAccessoryView 实现了一个自定义标注气泡,其中包含两个标签。
我知道如何用这条线改变 detailCalloutAccessoryView 的颜色。
view.detailCalloutAccessoryView?.backgroundColor = UIColor.red
但我不知道如何更改主气泡的背景颜色(现在是透明的灰色/白色)。使用view.detailCalloutAccessoryView?.backgroundColor = UIColor.red 行,我的 calloutbubble 看起来像这样:
但我希望我的自定义气泡看起来像这样:
这是我的viewFor注解方法:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let identifier = "pin"
var view : MKAnnotationView
if let dequedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) {
dequedView.annotation = annotation
view = dequedView
} else {
view = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
}
let pinImage = UIImage.init(named: "customPin")
DispatchQueue.main.async(execute: {
view.detailCalloutAccessoryView?.backgroundColor = UIColor.red
})
view.image = pinImage
configureDetailView(annotationView: view)
return view
}
我正在使用带有 Swift 3 的 Xcode 8。
知道如何将字体类型和标题的默认黑色从黑色更改为另一种颜色也会很有趣。 在详细视图中,我可以轻松更改 xib 文件中自定义标签的颜色,但不知道如何访问默认标题属性。
【问题讨论】:
标签: swift mkmapview mkannotation swift3 mkannotationview