Custom marker image on swift (MapKit)
我在 MapKit 上使用自定义标记
如何更改自定义标记上的图像宽度和高度?
我的代码:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if (annotation is MKUserLocation) { let reuseId =”test” var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) |
- 一种选择是您可以根据需要设置图像大小,然后您可以显示它。
尝试使用
1
|
anView.frame.size = CGSize(width: 30.0, height: 30.0)
|
1
2 3 |
var currentLocationAppleMarker : MKAnnotationView?
self.currentLocationAppleMarker?.image = //Image for Current Location Pin |
MapKit ViewForAnnotation 委托应该像,
1
2 3 4 5 6 7 8 9 10 11 |
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let pin = mapView.view(for: annotation) ?? MKAnnotationView(annotation: annotation, reuseIdentifier: nil) if annotation is MKUserLocation { pin.image = //Image for Current Location Pin return pin } else { pin.image = //Image for Other Pin return pin } } |
来源:https://www.codenong.com/30262269/