-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorPinAnnotation.swift
47 lines (36 loc) · 1.24 KB
/
ColorPinAnnotation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// ColorPinAnnotation.swift
// ColorPinAnnotationView
//
// Created by Daniel Saidi on 2015-08-18.
// Copyright (c) 2015 Daniel Saidi. All rights reserved.
//
/*
This is a help class that you can use to add colored
pins to your map view with minimum effort. You don't
have to use it in your apps; any MKAnnotation can be
used with a ColorPinAnnotation.
*/
import UIKit
import MapKit
public class ColorPinAnnotation: UIView, MKAnnotation {
public var title = ""
public var subtitle = ""
public var color = UIColor.redColor()
public var coordinate : CLLocationCoordinate2D {
get { return coordinateRegion.center }
set { coordinateRegion.center = newValue }
}
public var coordinateRegion = MKCoordinateRegion()
public func annotationViewForMapView(mapView:MKMapView) -> MKAnnotationView {
let id = "ColorPinAnnotation"
var view = mapView.dequeueReusableAnnotationViewWithIdentifier(id)
if (view == nil) {
view = ColorPinAnnotationView(annotation: self, reuseIdentifier: id)
}
if let customPin = view as? ColorPinAnnotationView {
customPin.pinColor = color
}
return view
}
}