【发布时间】:2015-11-04 22:00:23
【问题描述】:
我是 Swift 的新手。我正在尝试在特定引脚上使用不同颜色的引脚或自定义引脚。我的代码有效。我有一个紫色别针,但我想在它们之间有所作为。我该怎么做?我认为 MapView 委托方法有什么可做的,但我没有找到。
import UIKit
import MapKit
class MapsViewController: UIViewController , MKMapViewDelegate{
var shops: NSArray? {
didSet{
self.loadMaps()
}
}
@IBOutlet weak var map: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
loadMaps()
self.title = "Carte"
self.map!.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
// simple and inefficient example
let annotationView = MKPinAnnotationView()
annotationView.pinTintColor = UIColor.purpleColor()
return annotationView
}
func loadMaps(){
// navigationController?.navigationBar.topItem!.title = "Carte"
let shopsArray = self.shops! as NSArray
for shop in shopsArray {
let location = CLLocationCoordinate2D(
latitude: shop["lat"] as! Double,
longitude: shop["long"] as! Double
)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = shop["name"] as? String
annotation.subtitle = shop["addresse"] as? String
map?.addAnnotation(annotation)
}
// add point
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】: