swift - 自定义注释标注
问题描述
我正在尝试制作注释调用框,因为它没有颜色并且完全透明。
代码如下:
import Foundation
import MapKit
class CustomPin: NSObject, MKAnnotation
{
var coordinate: CLLocationCoordinate2D
var title: String?
init(pinTitle: String, location: CLLocationCoordinate2D) {
self.title = pinTitle
self.coordinate = location
}
}
func setPin(location: CLLocationCoordinate2D)
{
let pin = CustomPin(pinTitle:"" ,location: location)
self.mapView.addAnnotation(pin)
self.mapView.delegate = self
print(location.latitude)
print(location.longitude)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "customAnnotation")
annotationView.image = UIImage(named: "marker")
annotationView.canShowCallout = true
annotationView.detailCalloutAccessoryView = addressLabel
return annotationView
}
结果如下所示:
期望的结果应该是这样的:
有什么要修改的?
解决方案
我看了一点,我认为除了修改左右附件视图之外,Apple 没有任何你可以直接对标注外观做的事情。我认为您必须创建自己的自定义标注。
如果您尝试制作自己的自定义标注,请查看:https ://github.com/robertmryan/CustomMapViewAnnotationCalloutSwift
您还可以将此 Cocoapod 用于自定义标注:https ://github.com/okhanokbay/MapViewPlus
推荐阅读
- unity3d - Unity3D 错误“无效的构建路径”
- python - 为什么当需要 str 和 float 时 bool 和 int 不被视为类型错误?
- qml - 为什么 QML 变量不能大写?
- node.js - 使用 Google Cloud SDK shell 在 GAE 中部署
- bash - 对出现的行数进行排序和计数
- c - 错误:参数为
在 C 中初始化 - typo3 - 打字稿获取页面的uid
- azure - 无法连接到 Azure VM
- c++ - 如何修复 Visual Studio 2017 中的“命名空间 std 没有成员 scoped_lock”错误
- java - Java ConcurrentHashSet - 在多线程环境中对其进行迭代