การเปลี่ยนรูปของ pin image มีหลายแบบด้วยกัน เท่าที่ลองใช้งานดูมีดังนี้
- แบบ pin เป็นหมุด คลาส MKPinAnnotationView
- แบบ marker เป็นวงกลมมีปลายชี้ลงในแม็บ คลาส MKMarkerAnnotationView
- แบบใช้รูปภาพเอง คลาส MKAnnotationView
โดยหากต้องใช้รูปภาพเอง ให้ใช้คลาส MKAnnotationView ตัวอย่างเช่น
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// MARK: - MapView Delegate func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { let annotationReuseId = "Place" var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationReuseId) if anView == nil { anView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationReuseId) } else { anView.annotation = annotation } anView.image = UIImage(named: "annotation_pin") anView.backgroundColor = UIColor.clearColor() anView.canShowCallout = false return anView } |
แบบนี้ครับ ลองใช้กันได้เลยครับ
ขอบคุณที่มา https://markoau.wordpress.com/2015/06/11/set-a-custom-annotation-pin-image-on-mkmapview-in-swift/
0