自定义注释标注
Custom annotation call outs
我正在尝试制作注释标注框,因为它没有颜色并且完全透明。
代码如下:
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
}
结果是这样的:
想要的结果应该是这样的:
有什么要修改的?
我看了一点,我认为除了修改左右 accessoryViews 之外,Apple 没有任何可以直接对标注外观进行的操作。我认为您必须创建自己的自定义标注。
如果您想制作自己的自定义标注,请查看此内容:https://github.com/robertmryan/CustomMapViewAnnotationCalloutSwift
您还可以使用此 Cocoapod 进行自定义标注:https://github.com/okhanokbay/MapViewPlus
我正在尝试制作注释标注框,因为它没有颜色并且完全透明。
代码如下:
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
}
结果是这样的:
想要的结果应该是这样的:
有什么要修改的?
我看了一点,我认为除了修改左右 accessoryViews 之外,Apple 没有任何可以直接对标注外观进行的操作。我认为您必须创建自己的自定义标注。
如果您想制作自己的自定义标注,请查看此内容:https://github.com/robertmryan/CustomMapViewAnnotationCalloutSwift
您还可以使用此 Cocoapod 进行自定义标注:https://github.com/okhanokbay/MapViewPlus