0
迷你地图代码:广东话设置自定义图钉图像在图形页面,斯威夫特3
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)
}
为什么不工作?为什么我无法让自定义图像像针图一样工作?它适用于另一个视图控制器。 感谢提前
你设置你的viewController作为地图的委托? –
这是什么意思? – RandomGeek
加入您的viewDidLoad此行'self.ProfileMapView.delegate = self' –