gpt4 book ai didi

swift - 如何使用 detailCalloutAccessoryView 更改标注气泡的默认背景颜色

转载 作者:搜寻专家 更新时间:2023-10-31 08:32:00 25 4
gpt4 key购买 nike

在我的应用程序中,我有以下情况。

我已经实现了一个带有自定义 detailCalloutAccessoryView 的自定义标注气泡,里面有两个标签。

我知道如何使用此行更改 detailCalloutAccessoryView 的颜色。

view.detailCalloutAccessoryView?.backgroundColor = UIColor.red

但我不知道如何更改主气泡的背景颜色(现在是透明的灰色/白色)。使用 view.detailCalloutAccessoryView?.backgroundColor = UIColor.red 行我的 calloutbubble 看起来像这样:

enter image description here

但我希望我的自定义气泡看起来像这样:

enter image description here

这是我的 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。

了解如何将字体类型和标题的默认黑色从黑色更改为另一种颜色也很有趣。在详细 View 中,我可以轻松更改 xib 文件中自定义标签的颜色,但不知道如何访问默认标题属性。

最佳答案

   func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {

//design your custom view and set it to detailCalloutAccessoryView

view.detailCalloutAccessoryView = yourDetailView
detail.superview?.superview?.backgroundColor = yourColor
// This view is type of MKSmallCalloutView
}

关于swift - 如何使用 detailCalloutAccessoryView 更改标注气泡的默认背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39467838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com