Adapting PinTintColor to Ray Wenderlich tutorial for mapkit
Incase anyone else is following the tutorial and is seeing the following error: "'MKPinAnnotationColor' was deprecated in iOS 9.0: Use MKPinAnnotationView's pinTintColor instead"
Simply update the pinColor routine to return a UIColor instead.
func pinColor() -> UIColor { switch discipline { case "Sculpture", "Plaque": return UIColor.redColor() case "Mural", "Monument": return UIColor.purpleColor() default: return UIColor.greenColor() }}
And then make the corresponding call to set the pinTintColor like so:
view.pinTintColor = annotation.pinColor()
Instead of use property pinColor (deprecated), use property pinTintColor (iOS9)
//view.pinColor = MKPinAnnotationColor.Greenview.pinTintColor = UIColor.greenColor()//UIColor functionspublic class func blackColor() -> UIColor // 0.0 white public class func darkGrayColor() -> UIColor // 0.333 white public class func lightGrayColor() -> UIColor // 0.667 white public class func whiteColor() -> UIColor // 1.0 white public class func grayColor() -> UIColor // 0.5 white public class func redColor() -> UIColor // 1.0, 0.0, 0.0 RGB public class func greenColor() -> UIColor // 0.0, 1.0, 0.0 RGB public class func blueColor() -> UIColor // 0.0, 0.0, 1.0 RGB public class func cyanColor() -> UIColor // 0.0, 1.0, 1.0 RGB public class func yellowColor() -> UIColor // 1.0, 1.0, 0.0 RGB public class func magentaColor() -> UIColor // 1.0, 0.0, 1.0 RGB public class func orangeColor() -> UIColor // 1.0, 0.5, 0.0 RGB public class func purpleColor() -> UIColor // 0.5, 0.0, 0.5 RGB public class func brownColor() -> UIColor // 0.6, 0.4, 0.2 RGB public class func clearColor() -> UIColor // 0.0 white, 0.0 alpha
Here the full picture:
import MapKitclass MyAnnotation: MKAnnotation, NSObject { let identifier: String let title: String? let subtitle: String? let coordinate: CLLocationCoordinate2D init(identifier: String, title: String, subtitle: String, coordinate: CLLocationCoordinate2D) { self.identifier = identifier self.title = title self.subtitle = subtitle self.coordinate = coordinate super.init() } func mapItem() -> MKMapItem { let addressDictionary = [String(CNPostalAddressStreetKey): self.subtitle!] let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDictionary) let mapItem = MKMapItem(placemark: placemark) mapItem.name = self.title return mapItem }}func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{ if let annotation = annotation as? MyAnnotation { let identifier = annotation.identifier var view = MKPinAnnotationView() if let dequeuedView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as! MKPinAnnotationView! { view = dequeuedView view.annotation = annotation } else { view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) view.animatesDrop = true view.canShowCallout = true switch identifier { case "Sculpture", "Plaque": view.pinTintColor = UIColor.redColor() case "Mural", "Monument": view.pinTintColor = UIColor.purpleColor() default: view.pinTintColor = UIColor.greenColor() } } return view } return nil}