iOS 11.x Swift 4.0
据我所知,这应该可以,但是不能。它可以编译,但是不会改变图钉的颜色吗?
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
var view: MKAnnotationView! = mapView.dequeueReusableAnnotationView(withIdentifier: Constants.AnnotationViewReuseIdentifier) as? MKPinAnnotationView
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: Constants.AnnotationViewReuseIdentifier)
view.canShowCallout = true
view?.tintColor = .blue
} else {
view.annotation = annotation
}
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
view.leftCalloutAccessoryView = UIButton(frame: Constants.LeftCalloutFrame)
view.isDraggable = true
return view
}
我想念什么?
答案 0 :(得分:1)
假设您的 ViewController 符合 MKMapViewDelegate 协议,请替换下面的代码行:
d2; st ed
17 20
d3; st ed
13 13
25 30
与此
view?.tintColor = .blue
需要设置pinTintColor 来添加颜色。您可以了解有关 pinTintColor here
的更多信息希望这会有所帮助!