Change iOS 9 color contact Mapkit

I donโ€™t know how to change the code for the color of the buffer in iOS 9 (because Apple has recently changed the code for it), and I'm still new to Swift. So, I do not know how to integrate pinTintColor into my code now.

Below is the code:

 import UIKit import MapKit class ViewController: UIViewController, MKMapViewDelegate { @IBOutlet var map: MKMapView! override func viewDidLoad() { super.viewDidLoad() let annotation = MKPointAnnotation() let latitude:CLLocationDegrees = 40.5 let longitude:CLLocationDegrees = -74.6 let latDelta:CLLocationDegrees = 150 let lonDelta:CLLocationDegrees = 150 let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta) let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude) let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span) map.setRegion(region, animated: false) annotation.coordinate = location annotation.title = "Niagara Falls" annotation.subtitle = "One day bla bla" map.addAnnotation(annotation) } func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { // simple and inefficient example let annotationView = MKPinAnnotationView() annotationView.pinColor = .Purple return annotationView } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 
+1
source share
1 answer

pinColor deprecated in iOS 9, use pinTintColor .

Example:

 let annotationView = MKPinAnnotationView() annotationView.pinTintColor = UIColor.purpleColor() 

Although the OP specifically requests iOS 9, the following can guarantee that the non-debrecated method prior to iOS 9 can be called:

 if #available(iOS 9, *) { annotationView.pinTintColor = UIColor.purpleColor() } else { annotationView.pinColor = .Purple } 

If your minimum goal is iOS 9, as you specifically specify here, then the above will be redundant - Xcode will notify you of this with a warning, as well as for your information.

+6
source

Source: https://habr.com/ru/post/1234060/


All Articles