我不知道如何在iOS9中更改pin颜色的代码(因为苹果最近更改了它的代码),而且我在Swift中还是新手,所以,我现在不知道如何在我的代码中集成pinTintColor
。
请在下面找到我的代码:
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条答案
按热度按时间mccptt671#
pinColor
在iOS 9中已弃用,请改用pinTintColor
。示例:
虽然OP特别要求iOS 9,但以下内容可以确保可以调用iOS 9之前的“非弃用”方法:
如果你的最低目标是iOS9,就像你在这里特别要求的那样,那么上面的内容就是多余的-- Xcode会让你知道这一点,并给出警告,供你参考。