У меня есть MKAnnotations
настроен на карте, но я хотел бы изменить цвет аннотаций для разных сценариев. Есть ли способ изменить цвет аннотации?Как изменить цвет MKAnnation с помощью Swift?
Вот мой код ниже, как бы реализовать изменение цвета?
override func viewDidAppear(animated: Bool) {
var annotationQuery = PFQuery(className: "Post")
currentLoc = PFGeoPoint(location: MapViewLocationManager.location)
//annotationQuery.whereKey("Location", nearGeoPoint: currentLoc, withinMiles: 10)
annotationQuery.whereKeyExists("Location")
annotationQuery.findObjectsInBackgroundWithBlock {
(points, error) -> Void in
if error == nil {
// The find succeeded.
println("Successful query for annotations")
// Do something with the found objects
let myPosts = points as! [PFObject]
for post in myPosts {
let point = post["Location"] as! PFGeoPoint
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
annotation.title = post["title"] as! String!
annotation.subtitle = post["username"] as! String!
self.mapView.addAnnotation(annotation)
}
} else {
// Log details of the failure
println("Error: \(error)")
}
}
Если вы реализуете любые методы делегата, убедитесь, что на выходе из делегатов вид карты в раскадровке подключен к просмотру иначе ваши методы-делегаты не будут вызваны. – Anna