【发布时间】:2017-08-25 21:54:07
【问题描述】:
小地图代码:
import UIKit
import MapKit
@IBOutlet weak var ProfileMapView: MKMapView!
func mapView(_ ProfileMapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isMember(of: MKUserLocation.self) {
return nil
}
let reuseId = "ProfilePinView"
var pinView = ProfileMapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if pinView == nil {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
}
pinView!.canShowCallout = true
pinView!.image = UIImage(named: "CustomPinImage")
return pinView
}
override func viewDidLoad() {
super.viewDidLoad()
let LightHouseLocation = CoordinatesTemplate
// Drop a pin
let lightHouse = MKPointAnnotation()
lightHouse.coordinate = LightHouseLocation
lightHouse.title = barNameTemplate
lightHouse.subtitle = streetNameTemplate
ProfileMapView.addAnnotation(lightHouse)
}
为什么它不起作用?为什么我不能让我的自定义图像用作 pin 图像?它适用于我的另一个视图控制器。 先谢谢了
【问题讨论】:
-
您是否将 viewController 设置为地图委托?
-
这是什么意思?
-
在你的视图中添加DidLoad这一行
self.ProfileMapView.delegate = self -
如果能解决您的问题,请告诉我@RandomGeek
-
它做到了!谢谢 !你能把它作为一个答案,这样我就可以标记为正确了
标签: ios swift annotations mapkit mkpinannotationview